wp_mail (Wordpress mail function) not sending to g

2019-08-13 09:33发布

问题:

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?

回答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:

  • Use a "from" address that is a real address. WP default is wordpress@yourdomain.com. This can be filtered with wp_mail_from
  • Set the "sender" as the "from" address. Some spam filters reject email as spam if these two elements of the mail header do not match. There is a simple code snippet here that will do it.
  • Sending via SMTP is the best option. You can do this via a plugin (there are several in the wordpress.org plugin repository) or you can also set it up yourself using the phpmailer_init action.


回答2:

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/