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

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.

Read More

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>' . "rn";
$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?

Related posts

Leave a Reply

3 comments

  1. 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:

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