我使用Gmail SMTP从我使用CodeIgniter和PHP 5.3编写的Web应用程序发送电子邮件,直到最近才出现问题。这是我的代码片段:
$config['protocol'] = 'smtp';
$config['smtp_host'] = $this->smtp_host;
$config['smtp_port'] = $this->smtp_port;
$config['smtp_user'] = $this->smtp_username;
$config['smtp_pass'] = $this->smtp_password;
$config['mailtype'] = $this->email_type;
$config['newline'] = "\r\n";
$this->load->library('email', $config);
$this->email->from($email_sender, $email_sender_name);
$this->email->to($email_to);
$this->email->subject($message_subject);
$this->email->message($message_content);
$result = $this->email->send();
当我使用"ssl://smtp.gmail.com"
作为主机并使用465
作为端口时,我在日志中遇到此错误:
DEBUG - 2010-08-06 17:19:24 --> Email Class Initialized
ERROR - 2010-08-06 17:19:45 --> Severity: Warning --> fsockopen(): unable to connect to ssl://smtp.googlemail.com:465 (Connection timed out) /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1652
DEBUG - 2010-08-06 17:19:45 --> Language file loaded: language/english/email_lang.php
ERROR - 2010-08-06 17:19:45 --> Severity: Warning --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:19:45 --> Severity: Warning --> fgets() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1818
ERROR - 2010-08-06 17:19:45 --> Severity: Warning --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:19:45 --> Severity: Warning --> fgets() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1818
ERROR - 2010-08-06 17:19:45 --> Severity: Warning --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:19:45 --> Severity: Warning --> fgets() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1818
ERROR - 2010-08-06 17:19:45 --> Severity: Warning --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:19:45 --> Severity: Warning --> fgets() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1818
ERROR - 2010-08-06 17:19:45 --> Severity: Warning --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:19:45 --> Severity: Warning --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:19:45 --> Severity: Warning --> fgets() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1818
我不知道这是否相关,但在我将PHP升级到PHP 5.3
之前,相同的代码工作正常。如果这是防火墙或互联网连接问题,我仍然可以使用Thunderbird中的gmail smtp发送电子邮件。
在我查看各种论坛后,我得到了进行此测试的提示:
$ openssl s_client -starttls smtp -crlf -connect smtp.gmail.com:587
CONNECTED(00000003)
depth=1 /C=US/O=Google Inc/CN=Google Internet Authority
verify error:num=20:unable to get local issuer certificate
verify return:0
---
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=Equifax Secure Certificate Authority
---
Server certificate
-----BEGIN CERTIFICATE-----
...cut...
-----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 1901 bytes and written 335 bytes
---
New, TLSv1/SSLv3, Cipher is RC4-MD5
Server public key is 1024 bit
Compression: NONE
Expansion: NONE
SSL-Session:
Protocol : TLSv1
Cipher : RC4-MD5
Session-ID: 2CA08CABBE21653238292DEDF30D119428970FAA284263C92480DA5283AFE013
Session-ID-ctx:
Master-Key: B3F6D4423DC14E24E894D7AD7107B4A640839F2BF90233714EC5BF0D139611E65655902B50AEA3BD67373A21338526B0
Key-Arg : None
Start Time: 1281086948
Timeout : 300 (sec)
Verify return code: 20 (unable to get local issuer certificate)
---
250 ENHANCEDSTATUSCODES
使用相同的工具测试ssl
连接时会给我超时:
$ openssl s_client -ssl2 -crlf -connect smtp.gmail.com:465
connect: Connection timed out
connect:errno=110
我尝试在上面的代码中使用"tls://smtp.gmail.com"
作为主机和587
作为端口,但现在我收到此错误消息:
DEBUG - 2010-08-06 17:26:10 --> Email Class Initialized
ERROR - 2010-08-06 17:26:10 --> Severity: Warning --> fsockopen(): SSL operation failed with code 1. OpenSSL Error messages:
error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1652
ERROR - 2010-08-06 17:26:10 --> Severity: Warning --> fsockopen(): Failed to enable crypto /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1652
ERROR - 2010-08-06 17:26:10 --> Severity: Warning --> fsockopen(): unable to connect to tls://smtp.googlemail.com:587 (Unknown error) /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1652
DEBUG - 2010-08-06 17:26:10 --> Language file loaded: language/english/email_lang.php
ERROR - 2010-08-06 17:26:10 --> Severity: Warning --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:26:10 --> Severity: Warning --> fgets() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1818
ERROR - 2010-08-06 17:26:10 --> Severity: Warning --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:26:10 --> Severity: Warning --> fgets() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1818
ERROR - 2010-08-06 17:26:10 --> Severity: Warning --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:26:10 --> Severity: Warning --> fgets() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1818
ERROR - 2010-08-06 17:26:10 --> Severity: Warning --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:26:10 --> Severity: Warning --> fgets() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1818
ERROR - 2010-08-06 17:26:10 --> Severity: Warning --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:26:10 --> Severity: Warning --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:26:10 --> Severity: Warning --> fgets() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1818
ssl://smtp.gmail.com:465
tls
中使用PHP 5.3
吗?如果是,可以
你告诉我代码,所以我可以
它进入CodeIgniter并测试它。感谢。
答案 0 :(得分:1)
如果您从Google.com访问此页面以查找有关安全SMTP电子邮件的更多详细信息,请在CI论坛中查看此修补程序。
http://codeigniter.com/forums/viewthread/158882/
我的SMTP提供商(Exchange系统)不接受SSL连接,而是需要使用SMTP over TLS(STARTTLS,RFC 3207)。这是Email类的一个小补丁,它增加了对它的支持。它是针对1.7.2编写的。如果这对其他人有用,欢迎您将其纳入未来版本。
使用方法: 将服务器设置指定为常规SMTP服务器(tcp:// servername,通常为端口25或587)。 在config中启用新设置($ config ['starttls'] = TRUE;)
取决于TLS是否可用(即,在phpinfo()的“注册流套接字传输”部分中列出。)
答案 1 :(得分:0)
根据PHP文档,SSL和TLS都在4.3版本中添加。
http://de2.php.net/manual/de/function.fsockopen.php
所以,他们应该一般工作。
我找到了这个,它对我有用:
http://tareq.wedevs.com/2010/01/sending-mail-with-gmails-smtp-server-with-fsockopen/
也许你也可以尝试那个剧本。