The wp_mail function doesn’t work after updating WordPress to version 4.6.

My code is:

$headers="From: " . $this->from_name . ' <' . $this->from_email .'>' . "\r\n";
wp_mail( $service->getEmail(), $this->admin_daily_subject, $admin_daily_message, $headers );

It worked perfectly before the update. Also, I’ve noticed that sending emails doesn’t work in Contact Form 7.
Any ideas? Thanks in advance.

UPDATE

As I did not find the solution, I replaced wp_mail with mail function and added some headers:

$headers="From: " . $this->from_name . ' <'.$this->from_email.'>' . "\r\n" .
                           'Reply-To: '.$this->from_email . "\r\n" .
                           'X-Mailer: PHP/' . phpversion() . "\r\n" .
                           "Content-Type: text/html; charset=UTF-8";
mail( $service->getEmail(), $this->admin_daily_subject, $admin_daily_message, $headers );

With this update it works. I hope there will be some updates of wp codex about using wp_mail() with 4.6 or somebody will find a solutions.

UPDATE 2

It looks like I am not the only one that is facing this issue:

There was an error trying to send your message

3 Answers
3

The solution has been found here – Make WordPress Core

I’ve made changes in wp-includes/pluggable.php on line 352 from

$phpmailer->setFrom( $from_email, $from_name ); 

to

$phpmailer->setFrom( $from_email, $from_name, false ); 

And it works! Thanks to Marius L. J. (Clorith)!

Leave a Reply

Your email address will not be published. Required fields are marked *