最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【未解决】给wordpress添加smtp

WordPress crifan 9813浏览 0评论

【背景】

根据:

【记录】给wordpress添加评论回复发邮件通知功能

由于主机不支持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免费邮客户端设置的POP3、SMTP、IMAP地址

网易163免费邮箱相关服务器信息:

163免费邮客户端设置的POP3、SMTP、IMAP地址

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服务?

中的:

如何设置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后,再去访问:

http://localhost/phpinfo.php

其中phpinfo.php中的内容为:

<?php  
phpinfo();  
?>

然后可以看到对应的模块启用了:

sockets

Sockets Support

enabled

openssl

OpenSSL support

enabled

OpenSSL Library Version

OpenSSL 1.0.0d 8 Feb 2011

OpenSSL 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.

; http://php.net/from

;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-timeout

default_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:

from 2003 to green waste

然后点击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.然后参考:

Email from PHP

去把:

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.再参考:

新手问题,关于PHP发送邮件问题,等待高手解答

去改为:

[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.再参考:

XAMPP problem

去网上:

http://www.dllzj.com/DllDetail_php_smtp.dll.html

下载一个dll。结果其有很多版本。

所以又去:

http://localhost/phpinfo.php

确定是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

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (18)

  1. 佩服博主的勇气。我最近也尝试了N多方法,都没用。 打算放弃了。或者改用其他平台。
    旅行者博客8年前 (2016-01-07)回复
  2. 我快要放弃了 SMTP -> ERROR: Failed to connect to server: Connection timed out (110)
    Youth.霖9年前 (2015-08-14)回复
  3. 玩wordpress,就是可劲儿的折腾。。。博主加油!
    崔小可9年前 (2015-07-22)回复
  4. 一样的问题,弄了一晚上没解决!
    Jeffrey Colbert9年前 (2015-01-19)回复
  5. 只能说生命不休,折腾不止。佩服博主的折腾精神。为这个smtp问题操碎了心。后面屈服叻先使用着自带Mail函数,埋头准备写个脚本放到支持完全支持smtp的服务器上用的时候调用。。。
    九秒分享9年前 (2014-12-24)回复
  6. 直接打开php.ini文件,找到;extension=php_openssl.dll, extension=php_sockets.dll 将前面的分号;去掉,重启web服务器即可解决。 有的样做却发现ssl没有生效,那么有个办法,就是将ssleay32.dll和libeay32.dll文件拷贝到 C:\WINDOWS\system32 文件夹。
    liushichao11年前 (2013-11-11)回复
  7. 跟你一样的问题,尝试了各种方法,没用。没有这个无法自动邮件备份站点,也不能让用户正常注册…
    rove11年前 (2013-09-05)回复
  8. 试了这么多,我这前几天还可以,昨天就不行了也正查问题呢
    luger11年前 (2013-01-19)回复
  9. 你看看你的pfsockopen,可能也被禁用了。详情: http://zhourongyu.info/wordpress-the-send-problem/
    山荣11年前 (2012-12-06)回复
    • 谢谢提示,可惜仍未解决,详情见帖子中最后更新的内容。
      crifan11年前 (2012-12-06)回复
      • 怀疑是你的主机问题。你是在本地测试的?win环境下?
        山荣11年前 (2012-12-06)回复
        • 是的。主机环境,已更新至帖子最开始的部分。
          crifan11年前 (2012-12-06)回复
  10. 这个跟我的问题差不多一样,都是找不到SMTP主机
    bbis12年前 (2012-11-04)回复
    • 我后来的尝试是,在在线的网站所用的虚拟主机上测试,结果smtp发邮件等功能,就又都是好的了。 所以,貌似是当前主机要确保拥有此相关的邮件服务器类似的配置和功能的前提下,然后发邮件相关的,smtp相关的功能,好像才能正常使用的。
      crifan12年前 (2012-11-04)回复
      • 话说你真的是太有耐心了,不过看了你的文章我已经确定是主机的问题了,谢谢了
        ycvv11年前 (2013-09-01)回复
        • 我也是整了几天都没有搞好。我其他服务器的php也可以发邮件,还没把wp拿到其他服务器上去试。 之前用.net写了程序到wp的服务器上去,是可以发邮件的。但是wp死活发不出去邮件,我所有的邮件smtp/pop服务都开了的。就是发不出去,真的是郁闷了。
          Jeremy8年前 (2016-10-23)回复
92 queries in 0.170 seconds, using 22.26MB memory