Oops….the WordPress update broke my contactforms
One of the things i often have to implement on WordPress websites is contact-forms with a mail function.
Most of the time, I implement Contactform 7 because it is easy to comprehend for my customers and the function validation to get the emails sent to my customers’ email addresses, works fairly well.
Recently WordPress released version 4.6 and it had one Nasty surprise for me…… contact-forms suddenly didn’t work anymore.
Because this happened when I was handing over a website to a customer, I was wondering whether i had made a typo…
The wp_mail() function, which is being used by almost everything that wants to send emails from a WordPress website, according to the change log has been changed.
In 4.6 (see r38058) we changed how we apply the from email and name, we now use PHPMailers own setFrom()function call.
Sadly it has proven to be buggy. The good news is that it has been solved and a correct working function will be released with 4.6.1.
Until you can implement the 4.6.1. release in production, here’s the quickfix that solves your problem for now, however with a downside; you won’t be able to send attachements.
For Contactform 7:
I changed the wp_mail() function to mail() and removed $attachments. This is working for my setup with contact-form-7 4.5 and wordpress 4.6. Obviously without attachments.
see /wp-content/plugins/contact-form-7/includes/mail.php (Line 85)
return wp_mail( $recipient, $subject, $body, $headers, $attachments );
return mail( $recipient, $subject, $body, $headers );
Change it back once you have implemented 4.6.1. and verified that it works as expected.
Hope this helps