使用 WordPress wp_mail() 的电子邮件标题无效

问题描述 投票:0回答:1

当我尝试使用

WP Mail SMTP
发送电子邮件时,我收到无效标头,测试电子邮件工作正常。从 25.01 开始,它已经完美运行了几个月。它不起作用。

我的代码:

 $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>";
  }

错误:

invalid_parameter: Invalid headers 
php wordpress mime-types email-notifications email-headers
1个回答
0
投票

由于

wp_mail()
的默认字符编码是UTF-8,因此您不需要错误地实现
 charset=UTF-8
。另外,不需要 Mime 版本。

因此,假设所有其他变量都已正确定义,请尝试使用以下内容:

$headers  = "Content-Type: text/html;\r\n";
$headers .= "From: $email;\r\n";

if ( wp_mail( $to, $subject, $message, $headers ) ) {
    echo '<h3 style="color:green; text-align:center;">Email sent!</h3>';
} else {
    echo '<h3 style="color:red; text-align:center;">Email not sent!</h3>';
}

我已经删除了

$attachments
参数...如果您正在使用它,您可以重新定义它。

© www.soinside.com 2019 - 2024. All rights reserved.