php wp_mail(Wordpress 邮件功能)不发送到 gmail 或 live.co.uk 帐户

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20703958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:26:44  来源:igfitidea点击:

wp_mail (Wordpress mail function) not sending to gmail or live.co.uk accounts

phpjqueryajaxwordpressemail

提问by John T

I have a website that allows visitors to contact me two ways - via a contact form on it's own page and via an 'ajax' small contact form in the sidebar.

我有一个网站,允许访问者通过两种方式与我联系 - 通过其自己页面上的联系表和侧栏中的“ajax”小联系表。

Both forms of contact send an email to my gmail account.

这两种联系方式都会向我的 Gmail 帐户发送一封电子邮件。

The contact form on it's own page works fine but the ajax form doesn't send to gmail (nor does it send to email addresses ending in .live.co.uk)

它自己页面上的联系表单工作正常,但 ajax 表单不会发送到 gmail(也不会发送到以 .live.co.uk 结尾的电子邮件地址)

If I change the 'to' address on the ajax contact form to one of my other domains (i.e. a different email address) then it works fine.

如果我将 ajax 联系表单上的“收件人”地址更改为我的其他域之一(即不同的电子邮件地址),则它可以正常工作。

I've checked the headers of the emails that are sent and ended up installing a 'plugin' that alters the return-path in case Google (and live.co.uk) check this before accepting emails. This hasn't made any difference.

我检查了发送的电子邮件的标题并最终安装了一个“插件”,该插件可以改变返回路径,以防谷歌(和 live.co.uk)在接受电子邮件之前检查这个。这没有任何区别。

There is a lot of chatter on these forums and others about wp_mail not sending to gmail but no actual solution.

在这些论坛和其他论坛上有很多关于 wp_mail 没有发送到 gmail 但没有实际解决方案的喋喋不休。

I've checked the gmail spam folders etc in case the emails went in there but they are not.

我检查了 gmail 垃圾邮件文件夹等,以防电子邮件进入那里,但它们没有。

I've also tried using just the 'mail()' function but to no avail.

我也试过只使用 'mail()' 函数,但无济于事。

My code on the page that the ajax call goes to looks like this:

我在 ajax 调用所在页面上的代码如下所示:

$headers  = 'From: myWebsite <[email protected]>' . "\r\n";
$headers .= 'Reply-To: myWebsite <[email protected]>';
$email_to = "[email protected]";
wp_mail( $email_to , sanitize_text_field( $subjectLine ), wp_strip_all_tags( $emailContent ), $headers );
$email_to = "[email protected]";
wp_mail( $email_to , sanitize_text_field( $subjectLine ), wp_strip_all_tags( $emailContent ), $headers );

Everytime the form is submitted I get the email to my 'anotherdomain.com' address but not to my gmail.com address.

每次提交表单时,我都会将电子邮件发送到我的“anotherdomain.com”地址,但不会发送到我的 gmail.com 地址。

Any ideas?

有任何想法吗?

回答by butlerblog

A lot of these types of questions involve email not "sending" to certain domains. However, it is more likely that the email is not being received. "Not received" does not mean the same as "not sent" and this is an important distinction in troubleshooting.

许多此类问题涉及电子邮件不“发送”到某些域。但是,更有可能没有收到电子邮件。“未收到”与“未发送”的含义不同,这是故障排除中的一个重要区别。

If other email addresses are receiving, then it is likely that something is flagging your message at the receiving hosts that you listed.

如果其他电子邮件地址正在接收,则很可能是在您列出的接收主机上标记了您的邮件。

There are things that you can do to give your email a better chance of getting through without being dumped somewhere along the way:

您可以采取一些措施来让您的电子邮件有更好的机会通过,而不会被丢弃在某个地方:

回答by Vijayakumar Selvaraj

Hope these will help you, forgive me if my points are not valid.

希望这些对你有帮助,如果我的观点无效,请原谅我。

  1. Disable your headers & give a try, instead of from address use something like [email protected]
  2. Contact hosting provider & confirm your server is blacklisted by Gmail & .live.co.uk
  3. Try this plugin as well http://wordpress.org/extend/plugins/wp-mail-smtp/
  4. Read this article too http://www.butlerblog.com/2013/09/24/troubleshooting-the-wp_mail-function/
  1. 禁用您的标题并尝试一下,而不是从地址使用类似 [email protected] 的内容
  2. 联系托管服务提供商并确认您的服务器已被 Gmail 和 .live.co.uk 列入黑名单
  3. 也试试这个插件 http://wordpress.org/extend/plugins/wp-mail-smtp/
  4. 也请阅读这篇文章 http://www.butlerblog.com/2013/09/24/troubleshooting-the-wp_mail-function/

回答by Gavin

Just in case it might help someone, on my webhost if the From:and Reply-To:email addresses are the same then the email gets rejected. Just removing the Reply-To:header makes it work.

以防万一它可能对某人有所帮助,在我的虚拟主机上,如果电子邮件地址From:Reply-To:电子邮件地址相同,则电子邮件将被拒绝。只需删除Reply-To:标题即可使其工作。