【背景】
根据:
由于主机不支持mai()函数,所以需要给wordpress装对应的smtp。
注:
当前测试环境:
本地的localhost的wordpress
Win7 x64
PHP版本:5.3.6
Apache版本:Apache/2.2.19 (Win64) PHP/5.3.6
【解决过程】
1.登陆wordpress后台的插件页面,搜索“smtp”找到很多,
觉得WP Mail SMTP貌似不错,所以打算先去试试它。
2.装好后,启用,然后进入设置,全部使用默认设置,点击Send Test,产生对应结果:
Test Message Sent
The result was:
bool(true)The full debugging output is shown below:
。。。。。。
然后去看看是否收到测试邮件。
结果很悲催的是,没有收到。
靠,搞了半天,才看到,原来debug信息的最后是:
The SMTP debugging output is shown below:
SMTP -> ERROR: Failed to connect to server: No connection could be made because the target machine actively refused it. (10061)
The following From address failed: wordpress@localhost
即,根本没有成功发送。
看来还是需要改写参数配置才行的。
2.然后填写了一堆的信息,再去测试,结果还是出错:
Test Message Sent
The result was:
bool(true)The full debugging output is shown below:
。。。
The SMTP debugging output is shown below:
SMTP -> ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060)
The following From address failed: [email protected]
3.然后就去网上参考了:
SAE的WordPress通过wp-mail-smtp插件实现发邮件功能
WordPress如何发邮件——插件wp-mail-smtp的使用
对于“Authentication ”,选中“Yes: Use SMTP authentication.”
再对于“Return Path ”选上“Set the return-path to match the From Email”
结果还是这个错误:
SMTP -> ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060)
其中,我所设置的是163的,其smtp可以在这里查到:
网易163免费邮箱相关服务器信息:
4.后来试了试我自己网站的crifan.com的邮箱,也还是同样错误。
5.又试了试qq的邮箱,也还是同样问题。
(已经去qq中开启了smtp:
去qq中启用:
POP3/IMAP/SMTP/Exchange服务
开启服务:
POP3/SMTP服务 (如何使用 Foxmail 等软件收发邮件?)
IMAP/SMTP服务 (什么是 IMAP,它又是如何设置?)
Exchange服务 (什么是Exchange,它又是如何设置?)
)
然后试了试qq的ssl,如果本身qq中没有开启ssl的话,点击“send test”则会立刻出错:
SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" – did you forget to enable it when you configured PHP? (5)
(相比较而言,如果正常使用费ssl去测试,则是需要一段时间后,才出现10060的错误的)
再勾选“https安全连接:在邮箱内,全程使用https安全链接。(什么是https?)“
(对应的qq关于ssl的介绍,可参考:
中的:
如何设置IMAP服务的SSL加密方式?
如果您的电子邮件客户端支持SSL,可以在设置中选择使用SSL。
使用SSL的通用配置如下:
接收邮件服务器:imap.qq.com,使用SSL,端口号993
发送邮件服务器:smtp.qq.com,使用SSL,端口号465或587
账户名:您的QQ邮箱账户名(如果您是VIP帐号或Foxmail帐号,账户名需要填写完整的邮件地址)
密码:您的QQ邮箱密码
电子邮件地址:您的QQ邮箱的完整邮件地址
)
然后此处选上“Use SSL encryption”,不论是25的端口还是465或587的端口,结果还是同样错误提示
SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" – did you forget to enable it when you configured PHP? (5)
6.参考:
WP-Mail-SMTP使用Gmail的SMTP服务来代发邮件失败的解决方法
也试了试gmail,选的是Use TLS encryption,结果错误依旧。
7.实在无法搞定了。
再去试试
Configure SMTP
结果出错:
An error was encountered while trying to send the test e-mail.
SMTP Error: Could not connect to SMTP host.
参考:
Could not connect to SMTP host错误的解决方法
8.然后又参考:
【WordPress】“SMTP Error: Could not connect to SMTP host.”的解决办法
去把php.ini中的
;extension=php_sockets.dll
;extension=php_openssl.dll
改为:
extension=php_sockets.dll
extension=php_openssl.dll
然后重启了服务中的Apache 2.2后,再去访问:
其中phpinfo.php中的内容为:
<?php
phpinfo();
?>
然后可以看到对应的模块启用了:
sockets
Sockets Support
enabledopenssl
OpenSSL support
enabledOpenSSL Library Version
OpenSSL 1.0.0d 8 Feb 2011OpenSSL Header Version
OpenSSL 0.9.8r 8 Feb 2011
然后再去测试“Configure SMTP”之前错误没了,但出现新的错误:
An error was encountered while trying to send the test e-mail.
Could not instantiate mail function.
9. 所以,再去试试启用之前的“WP Mail SMTP”,结果竟然也是同样错误:
The SMTP debugging output is shown below:
Could not instantiate mail function.
10.再去把之前的改动都改回来,包括:
把
$this->Mailer = ‘SMTP’;
改回:
$this->Mailer = ‘smtp’;
把
$this->smtp_conn = @pfsockopen($host, // the host of the server
改回
$this->smtp_conn = @fsockopen($host, // the host of the server
再重启一下apache 2.2,
结果竟然又出现了之前的问题了:
SMTP -> ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060)
所以还是要把上述改动再加上。
先单独试试:
$this->smtp_conn = @fsockopen($host, // the host of the server
改为
$this->smtp_conn = @pfsockopen($host, // the host of the server
同样错误,再把
$this->Mailer = ‘smtp’;
改为
$this->Mailer = ‘SMTP’;
然后重启apache
错误变成:
The SMTP debugging output is shown below:
Could not instantiate mail function.
11.然后同样参考上述帖子,把465改为587试试。
结果还是不行。
12.又回到“Configure SMTP Settings”界面,启用了debug后,结果错误其实和之前是一样的:
SMTP -> ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060)
对应着显示的错误是:
An error was encountered while trying to send the test e-mail.
SMTP Error: Could not connect to SMTP host.
13.折腾了半天,仍然是不能工作。
看到这里:
WP Mail SMTP SMTP -> ERROR: Failed to connect to server: Connection timed out (110)
以及
WP Mail SMTP SMTP ERROR Failed to connect to server Connection timed out 110
说是和php的fopen有关
然后去php.ini中找了下fopen,只找到这些配置:
;;;;;;;;;;;;;;;;;;
; Fopen wrappers ;;;;;;;;;;;;;;;;;;;
; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
; http://php.net/allow-url-fopen
allow_url_fopen = On
; Whether to allow include/require to open URLs (like http:// or ftp://) as files.
; http://php.net/allow-url-include
allow_url_include = Off
; Define the anonymous ftp password (your email address). PHP’s default setting
; for this is empty.;from="[email protected]"
; Define the User-Agent string. PHP’s default setting for this is empty.
; http://php.net/user-agent;user_agent="PHP"
; Default timeout for socket based streams (seconds)
; http://php.net/default-socket-timeoutdefault_socket_timeout = 60
; If your scripts have to deal with files from Macintosh systems,
; or you are running on a Mac and need to deal with files from; unix or win32 systems, setting this flag will cause PHP to
; automatically detect the EOL character in those files so that
; fgets() and file() will work regardless of the source of the file.
; http://php.net/auto-detect-line-endings
;auto_detect_line_endings = Off
看起来,也没啥需要改的。
不过,倒是觉得,的确有可能是当前主机环境下,某些smtp之类的东西被封了,所以无法去发邮件。
所以等换到另外一个环境,再去试试看看能否发送邮件。
【后记1 2012-12-06】
1.之前就已经折腾过了,已经确认,可以实现,搭在HostMonster上的,在线的wordpress中,正常的发送邮件的。
2. 刚去参考WordPress的邮件发送问题中的提示,去看了看本地的:
D:\tmp\WordPress\DevRoot\php-5.3.6-Win32-VC9-x64\php.ini
其中相关配置为:
; Whether to allow the treatment of URLs (like http:// or ftp://) as files. ; http://php.net/allow-url-fopen allow_url_fopen = On ...... ; This directive allows you to disable certain functions for security reasons. ; It receives a comma-delimited list of function names. This directive is ; *NOT* affected by whether Safe Mode is turned On or Off. ; http://php.net/disable-functions disable_functions =
很明显,没有被禁用的函数。但是结果仍是无法发送邮件的。
所以,问题仍未解决。
【后记2 2012-12-06】
1.再去参考各种帖子,先去登陆本地wordpress后台:
http://localhost/wp-admin/options-general.php?page=wp-mail-smtp/wp_mail_smtp.php
去配置mail:
然后点击Send Test去测试。
结果出现,之前就有的错误:
The SMTP debugging output is shown below:
SMTP -> ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060)
2.然后参考:
去把:
D:\tmp\WordPress\DevRoot\php-5.3.6-Win32-VC9-x64\php.ini
中的:
[mail function] ; For Win32 only. ; http://php.net/smtp SMTP = localhost ; http://php.net/smtp-port smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from ;sendmail_from = [email protected]
改为:
[mail function] ; For Win32 only. ; http://php.net/smtp ;SMTP = localhost SMTP = 163.com ; http://php.net/smtp-port smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from ;sendmail_from = [email protected] sendmail_from = [email protected]
然后,重启Apache,再去试试上述邮件测试。
结果同样错误:
The SMTP debugging output is shown below:
SMTP -> ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060)
3.再参考:
去改为:
[mail function] ; For Win32 only. ; http://php.net/smtp ;SMTP = localhost SMTP = smtp.163.com ; http://php.net/smtp-port smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from ;sendmail_from = [email protected] sendmail_from = [email protected]
然后再去试试效果。
结果错误依旧。
4.再参考:
去网上:
http://www.dllzj.com/DllDetail_php_smtp.dll.html
下载一个dll。结果其有很多版本。
所以又去:
确定是PHP Version 5.3.6,然后把其中,相对最新的5.2.6.6的php_smtp.dll,拷贝到:
D:\tmp\WordPress\DevRoot\php-5.3.6-Win32-VC9-x64\ext\
再去到:
D:\tmp\WordPress\DevRoot\php-5.3.6-Win32-VC9-x64\php.ini
添加对应的:
extension=php_smtp.dll
再重启apache,再去测试邮件发送。
结果问题依旧。
5.再去随便试试,php.ini中改为:
extension=php_openssl.dll
extension=php_sockets.dll
重启apache,再试试。结果错误依旧。
6.另外找了半天,也还是没有找到更新版本的php_smtp.dll。
7.选上“Set the return-path to match the From Email”试试效果。
结果问题依旧。
8.再试试,改回:
“Use the PHP mail() function to send emails.”
试试。
结果错误又变成了:
Could not instantiate mail function.
9.后来又参考了:
Could not instantiate mail function
更加明白了一点是:
由于当前是本地localhost的wordpress,而本地的电脑,没有邮件服务器功能,
所以,没法通过当前PC去发送邮件的,所以出现了“Could not instantiate mail function”是正常的。
解决办法就是,使用外部的smtp。
即,此处就是,从:
“Use the PHP mail() function to send emails.”
切换到,之前就设置的那个:
“Send all WordPress emails via SMTP.”
即,类似于我之前用过163邮箱中的,邮件代发功能。
提供对应的smtp服务器,提供对应的端口,邮箱用户名和密码,然后让人家帮你发送,就可以了。
10.所以,接下来,还是应该给予使用smtp方面,看看如何搞定此问题。
截止目前,感觉:
要么是php.ini中某些配置有误;
要么是php_smtp.dll有问题。
11.把SMTP Host从smtp.163.com改为mail.163.com试试。
结果还是不行。
12.去
http://windows.php.net/download/
下载
http://windows.php.net/downloads/releases/php-5.3.19-Win32-VC9-x86.zip
13.参考了:
Sendmail using Gmail SMTP server to send emails from ProjectPier
和
PHP Mail using Gmail SMTP Tutorial
结果也还是没用。
【总结】
暂时还是没有完全搞懂这部分的背后逻辑,还是没解决问题。
转载请注明:在路上 » 【未解决】给wordpress添加smtp