I get an invalid header when I try to send an email using WP Mail SMTP, the test emails work fine. It has been working perfectly for months but from 25.01. it is not working.
My code:
$headers = "From: $email\n;";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8";
if (wp_mail($to, $subject, $message, $headers, $attachments)) {
echo "<h3 style='color:green; text-align: center;'>Email sent!</h3>";
}
Error thrown: invalid_parameter: Invalid headers
As the default character encoding for
wp_mail()is UTF-8, you don't needcharset=UTF-8and also, the Mime version is not needed.So assuming that all other variables are correctly defined, try to use the following instead:
Tested and works in last WordPress version.
I have removed
$attachmentsargument… If you are using it, you can define it back.