Loading
0

WP Mail SMTP插件解决WordPress邮件收发失败问题

对于WordPress建站的用户来说,用户在线注册、找回密码等基本功能都是需要用到邮箱收发功能的,对于有些主机因为不支持或者是禁用了mail()函数,导致无法实现在线邮件收发功能;而对于WordPress企业站用户来说,如果使用了Contact Form 7表单插件的话,那也会无法实现用户无法提交表单的现象。那么,本文就为大家介绍一款解决这一问题的优秀插件:WP Mail SMTP

WP Mail SMTP 插件其实就是在主机或服务器无法使用mail()函数的时候,来完成这项工作的一款插件。插件的功能单一,设置简单,按照设置中的介绍填写几个与邮箱服务有关的参数就可以正常地发送邮件了。

WP Mail SMTP插件解决WordPress邮件收发失败问题

WordPRess SMTP 的插件有很多,简单的试用之后:WP Mail SMTP 可以说是目前最好的一个,这个插件重新设定了 WordPress 的 wp_mail() 函数,使它能够试用 SMTP 的方式发送邮件,并且还提供了设置页面让你输入 SMTP 的详细信息:

  • 指定发送的邮箱和名称
  • 设置试用 SMTP 或者 mail() 函数来发送。
  • 指定 SMTP 服务器地址。
  • 指定 SMTP 服务器端口。
  • 设置 SSL 还是 TLS 加密。
  • 设置是否启用 SMTP 验证。
  • 设置 SMTP 的用户名和密码。

每个选项边上都有相关说明.在插件作者的网站中介绍是这样:

  1. From Email: “yourusername@domain.com” (without the quotes). This must be your GoDaddy hosted e-mail account.
  2. From Name: type in either your name or the name of your website. This will make the From line of the e-mail read as “From Name” <yourusername@domain.com>.
  3. Mailer: Choose “Send all WordPress emails via SMTP”. Do not choose the “…PHP mail() function…” because it won’t work.
  4. SMTP Host: relay-hosting.secureserver.net (do not use the SMTP server that GoDaddy provided you during your e-mail account sign-up. For the record, that is smtpout.secureserver.net).
  5. SMTP Port: 25 (default for most SMTP servers).
  6. Encryption: Choose “No encryption”. (I hope you aren’t sending sensitive data!)
  7. Authentication: Choose “No: Do not use SMTP authentication”.
  8. Click the Update Options button. You will be taken to the General Settings tab.
  9. Now click the Email link again. Scroll down to the bottom of the page and type in a valid e-mail address in the To: box under the “Send a Test Email” section.
  10. Click the Send Test button.

作者的说明是以Godaddy主机为例.结合实际情况具体的配置如下:

  • “From Email”项表示你收到的所有从该WordPress发出的邮件(包括Contact Form 7中用户提交的表单内容,收到评论的通知邮件,重置WP登陆密码的密码找回邮件)都是从这个邮箱发出.该邮箱取代了WordPress自带的那个邮件发件人.要注意的是,如果这一项不填则默认与Setting-General-Email Address(设置-通用中的邮箱地址)相同;如果要填你希望的发送邮箱,例如选用Gmail,QQ邮箱等支持SMTP的邮箱,这个时候一定记得进入Setting-General中把Email Address改为与这个选项相同的邮箱,否则WP Mail SMTP是不能正常工作的.
  • “From Name”项表示你收到来自”From Email”的邮件时显示的发件人名字,可随意填你喜欢的.
  • “Maile”项选择”Send all WordPress emails via SMTP”.否则你还要WP Mail SMTP干嘛?
  • “Return Pat”建议勾选.
  • “SMTP Host”以及”SMTP Port”根据你在”From Email”填写的邮箱来填写.我使用的是QQ企业邮箱,因此”SMTP Host”填写”smtp.exmail.qq.com”,Port为25.如果是QQ邮箱,则”SMTP Host”为”smtp.qq.com”,Port也是25;如果是Gmail,”SMTP Host”为”smtp.gmail.com”,Port为465;其他邮箱可在邮箱设置中获取SMTP Host和Port.
  • “Encryption”加密方式,QQ邮箱为No encryption,Gmail选择Use SSL encryption.其他邮箱自行搜索.
  • “Authentication”一般选择”Yes: Use SMTP authentication”,否则下面的用户名和密码就无效了.
  • “Username”为”From Email”中填写的邮箱,”Password”填写实际登陆”From Email”邮箱的密码,比如”From Email”用的是QQ邮箱则”Password”就是QQ密码.不过WP Mail SMTP在这里密码竟然用明文显示,应该算是插件的缺陷之一.

以上选项填写完毕后点击保存设置.这时候可以在下面的”Send a Test Email”中填写一个你的常用邮箱地址试一下能否发送成功.如果结果是bool(true)则证明设置正确,这个时候WordPress中收到评论应该已经可以发送通知邮件到你的”From Email”邮箱提醒你了.

WP Mail SMTP 插件下载地址:http://wordpress.org/plugins/wp-mail-smtp/

WP Mail SMTP的设置到这里就搞定了.接下来不妨先试用一下Contact Form 7默认的表单,将代码复制到任何post/page中,再从前台进入这个页面提交一份测试表单,如果能成功提交,那么Contact Form 7就是工作正常的,这个时候Contact Form 7设置中的”To”邮箱应该就收到一封来自”From Email”的表单内容的邮件.

如果WP Mail SMTP工作正常,但是Contact Form 7的表单仍然不能成功提交,还是提示”Failed to send your message. Please try later or contact the admin”,则说明Contact Form 7中设置有问题.我就是在这里摸索了很长时间,看了网上不少解决办法,但是这一步都没有详细的描述.参考页面有:

  • How to Send Email with WordPress from GoDaddy (Windows Hosting)
  • Contact Form 7 FAQ
  • Contact Form 7 + WP-Mail-SMTP + Godaddy E-mail not working

最后发现其实只要将Contact Form 7中表单设置里的”From”的邮箱改为之前在WP Mail SMTP中设置的邮箱就可以搞定.

WP Mail SMTP插件解决WordPress邮件收发失败问题

如上图第二栏”From”中原本默认设置的是”[your-name]<[your-mail]>”,这个时候Contact Form 7总是以用户输入的邮箱,即[your-mail]作为邮件发送者,但是由于空间是不支持邮件发送的,因此这样永远都是提示发送失败.将”<[your-mail]>”改为<”From Email”>问题就解决了.例如”From”栏中填入[your-name]<example@capbone.com>,前提是在WP Mail SMTP设置中的”From Email”也是example@capbone.com.

这个时候再复制Contact Form 7某个表单生成的代码到任意post/page中,在前台应该就能顺利提交了.

教程参考