使用 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 smtp
1个回答
0
投票

由于

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

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

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

    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>';
    }
© www.soinside.com 2019 - 2024. All rights reserved.