利用WP Mail SMTP插件解决WordPress中Contact Form 7发送失败问题

Contact Form 7 是 WordPress 下一款功能强大,操作灵活的表单生成插件,可以作为网站联系页面的联系人信息表单提交,或是用于其他一些需要用户提交表单的场合.可 以自定义不同类型的表单功能,支持自定义接受邮件,Ajax 提交和 jQuery 表单插件支持.可结合 Akismet 过滤垃圾邮件,也支持 CAPTCHA 反垃圾邮件.表单域元素支持单选框,复选框,文本框,下拉菜单,按钮,文件上传等多种表单域.具体介绍可以在WordPress中插件页面以及插件主页看到.

但是我在使用过程中每次向 Contact Form 7 提交任何信息都收到发送失败的提示"Failed to send your message. Please try later or contact the admin",再想起来每次收到评论后也无法收到邮件通知,联系了一下主机提供商才知道我使用的空间是不支持邮件发送的,并建议我使用WP Mail SMTP插件.

上网搜索了一下发现不少主机空间都是不支持邮件发送的,一般都使用 WP Mail SMTP 或者 Cimy Swift SMTP 来解决. Cimy Swift SMTP 我没有使用过,因此不做介绍. WP Mail SMTP 其实就是在主机或服务器无法使用mail()函数的时候,来完成这项工作的一款插件(插件下载页面插件作者博客).

插件的功能单一,设置也不复杂,按照设置中的介绍填写几个与邮箱服务有关的参数就可以正常地发送邮件了.

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

  • From Email: “yourusername@domain.com” (without the quotes). This must be your GoDaddy hosted e-mail account.
  • 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>.
  • Mailer: Choose “Send all WordPress emails via SMTP”. Do not choose the “…PHP mail() function…” because it won’t work.
  • 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).
  • SMTP Port: 25 (default for most SMTP servers).
  • Encryption: Choose “No encryption”. (I hope you aren’t sending sensitive data!)
  • Authentication: Choose “No: Do not use SMTP authentication”.
  • Click the Update Options button. You will be taken to the General Settings tab.
  • 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.
  • 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的设置到这里就搞定了.接下来不妨先试用一下 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中设置有问题.我就是在这里摸索了很长时间,看了网上不少解决办法,但是这一步都没有详细的描述.参考页面有:

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

如上图第二栏"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中,在前台应该就能顺利提交了.

下图是我生成的一个联系表单,相比默认表单增添了一个上传附件的功能.可以在Contact页面(capbone.com/contact/)看到.


15 Comments

  1. yiwu agent 2015-12-03 Reply

    You help me to solve this problem, thank you very much!

  2. Kelvin 2014-07-25 Reply

    Dear bro, I saw your post and followed up the steps and I succeeded in showing “Your email was successfully sent. We will be in touch soon.”
    But I got the another problems, my “From Email” has always received and Error Email writing that “Delivery to the following recipient failed permanently: Technical details of permanent failure: “. I have no idea, please help me bro

    • Author
      Captain 2014-07-28 Reply

      Sorry it was long time ago since I’ve used this plugin last time,I’ve forgotten most of details about it.All I can suggest is that you might go to check the setting of your enterprise mail.I used Tencent enterprise mail and everything went well with WP Mail SMTP.

  3. I am not sure where you’re getting your info, but
    good topic. I needs to spend some time learning more or understanding
    more. Thanks for fantastic info I was looking for this info for
    my mission.

  4. Thank you a bunch for sharing this with all people you actually understand what
    you are talking about! Bookmarked. Please also consult
    with my site =). We coould have a hyperlink alternate contract among us

  5. Dave 2014-04-16 Reply

    I absolutely love your site.. Excellent colors & theme.
    Did you develop this website yourself? Please reply back as I’m hoping to create my very own blog and
    want to find out where you got this from or what the theme
    is called. Cheers!

    • Author
      Captain 2014-04-16 Reply

      You can search keyword Flexform in Themeforest

  6. medileen 2014-03-20 Reply

    When I originally commented I clicked the “Notify me when new comments are added” checkbox and
    now each time a comment is added I get several e-mails with the same comment.
    Is there any way you can remove me from that service?
    Thanks a lot!

    • Author
      Captain 2014-03-20 Reply

      I didn’t see the “Notify me when new comments are added” checkbox at all.Where is this option?

  7. moncler outlet 2013-09-23 Reply

    Hi,thanks’s for help me find the answer

  8. Miami International Airport is now among the only airports inside the nation with six lanes particularly created for members on the Global Entry program.

Leave a reply

Your email address will not be published.