wp_mail (Wordpress mail function) not sending to g

2019-08-13 09:32发布

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.

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

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)

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.

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.

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

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

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

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

$headers  = 'From: myWebsite <enquiries@mywebsite.co.uk>' . "\r\n";
$headers .= 'Reply-To: myWebsite <enquiries@mywebsite.co.uk>';
$email_to = "myemailaddy@gmail.com";
wp_mail( $email_to , sanitize_text_field( $subjectLine ), wp_strip_all_tags( $emailContent ), $headers );
$email_to = "myemailaddy@anotherdomain.com";
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.

Any ideas?

2条回答
疯言疯语
2楼-- · 2019-08-13 10:03

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 wordpress@mywebsite.co.uk
  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/
查看更多
放我归山
3楼-- · 2019-08-13 10:12

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:

查看更多
登录 后发表回答