我阅读了很多文章,他们解释了如何使用smtp发送电子邮件,例如
Send email using GMail SMTP server from PHP page
我有一个云服务器和一个localhost设置,两者都是相同的(Centos 6,只通过yum安装了httpd,PHP和MysqL).
iptables是相同的:打开输出端口,仅输入22和80.
我安装了梨邮件和梨Net_SMTP与smtp.gmail.com一起使用.
的PHPinfo();显示openssl已启用.
我正在使用此代码:
<?PHP require_once "Mail.PHP";
$from = "<from.gmail.com>";
$to = "<to.yahoo.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "<myaccount.gmail.com>";
$password = "password";
$headers = array ('From' => $from,'To' => $to,'Subject' => $subject);
$smtp = Mail::factory('smtp',array ('host' => $host,'port' => $port,'auth' => true,'username' => $username,'password' => $password));
$mail = $smtp->send($to,$headers,$body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?> <!-- end of PHP tag-->
在我的localhost服务器上,脚本工作,我收到了我的Gmail帐户的电子邮件.但是在我的云服务器上,使用相同的脚本,我收到了这个错误:(使用调试)
ErrorFailed连接到ssl://smtp.gmail.com:465 [SMTP:无法连接套接字:权限被拒绝(代码:-1,响应:))DEBUG:发送:QUIT
我搜索了很多,我看到有人说当465端口被阻塞时会发生错误.
所以我查看了我的iptables,我的连接等,并打开了OUTPUT的端口465.
我做了一个测试:
openssl s_client -verify 0 -connect smtp.gmail.com:465
我得到了这个结果:
verify depth is 0
CONNECTED(00000003)
depth=2 C = US,O = Equifax,OU = Equifax Secure Certificate Authority
verify return:1
depth=1 C = US,O = Google Inc,CN = Google Internet Authority
verify return:1
depth=0 C = US,ST = California,L = Mountain View,CN = smtp.gmail.com
verify return:1
---
Certificate chain
0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=smtp.gmail.com
i:/C=US/O=Google Inc/CN=Google Internet Authority
1 s:/C=US/O=Google Inc/CN=Google Internet Authority
i:/C=US/O=Equifax/OU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vagbdnBLAkdhvAf90B5a
9beBxJH2/ylTSIGfD2uceAqzcsQe6Ouy4C9r3rz86qA1dhdtIcPg6uoZb+E2qhE5
UaOJOPO4rHInX9kscBxh+baHbpBMh+ch6v5L8plss8hd0id8C4g10YKzwcgPYlQ=
-----END CERTIFICATE-----
subject=/C=US/ST=California/L=Mountain View/O=Google Inc/CN=smtp.gmail.com
issuer=/C=US/O=Google Inc/CN=Google Internet Authority
---
No client certificate CA names sent
---
SSL handshake has read 1850 bytes and written 299 bytes
---
New,TLSv1/SSLv3,Cipher is RC4-SHA
Server public key is 1024 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
Protocol : TLSv1
Cipher : RC4-SHA
Session-ID: 55E90A8854BB04C962AB8AD7D231C89291E62B28EC93F4189CFD512B2EFD43B6
Session-ID-ctx:
Master-Key: C454B3ED7E5C522B745F0E2EBF45BDEADFAD2CE29ECE945C1CA6EBA1629921577FEECFF968D896E39CF4E0057731CD26
Key-Arg : None
Krb5 Principal: None
PSK identity: None
PSK identity hint: None
TLS session ticket lifetime hint: 100800 (seconds)
TLS session ticket:
0000 - 75 be ab 14 ff bf e3 74-61 4f 98 e6 ec 58 ae ab u......taO...X..
0010 - 50 2f 20 f5 12 14 ae b5-11 dd 2c c1 9e 99 36 b1 P/ .......,...6.
0020 - 9a 66 5b 76 15 c8 0e 7f-07 ce ce e1 4c b3 f4 12 .f[v........L...
0030 - 38 c8 43 2d a2 c7 f9 62-17 4f da 82 4f 4b 12 93 8.C-...b.O..OK..
0040 - af 31 9e d5 90 8d 3e 4c-06 d6 73 30 fb b6 95 80 .1....>L..s0....
0050 - 59 1c 65 e3 d3 51 2e a7-48 15 11 ba 9f 72 89 12 Y.e..Q..H....r..
0060 - 9a 68 63 df 65 22 0f cb-60 b7 cf 3c b4 c6 f9 92 .hc.e"..`..<....
0070 - a0 c1 34 d7 06 31 97 ef-e6 8a bf b8 14 d9 72 b0 ..4..1........r.
0080 - 13 d9 dd df ce 48 a1 83-74 53 d6 fe b0 5a 53 a1 .....H..tS...ZS.
0090 - ee d0 9e b3 ....
Start Time: 1335462088
Timeout : 300 (sec)
Verify return code: 0 (ok)
---
所以,我认为问题与“阻塞端口”没有关系.
我也试过587端口……
我给我的主人发了一条消息,询问ISP是否可以阻止这些端口,他们告诉我他们不阻止任何端口,客户端(我)可以完全控制服务器.
我不知道还有什么可以导致这个错误以及我现在能做些什么.
也许我没有看到一些配置文件.
任何人都有一些建议来帮助我或建议我可以做更多的测试,以获得更多信息,为什么我得到该错误并解决这个问题?
谢谢