在 wp_mail header 中设置 reply-to 地址

Set reply-to address in wp_mail header

我使用 wp_mail 从我的 WordPress 主题发送通知。我如何将 reply-to 地址添加到以下 wp_mail 脚本:

$recipient  = "recipient@example.com";
$headers = array('Content-Type: text/html; charset=UTF-8','From: MyWebsite <'mywebsite@example.com'>');
$message = 'Here is the sent message';
        
wp_mail( $recipient, 'Here comes the Subject', $message, $headers );     

   

您可以在$headers数组中设置回复地址。它需要在 <> 中包含电子邮件地址,我建议使用名称以确保一切正常。

$headers[] = 'Reply-To: Firstname Lastname <your@mail.com>';

我为您的电子邮件添加了主题。所以你的代码看起来像:

$recipient  = "recipient@example.com";
$subject = "Your subject";
$message = "Here is the sent message";
$headers = array(
    'Content-Type: text/html; charset=UTF-8',
    'From: MyWebsite <mywebsite@example.com>',
    'Reply-To: Firstname Lastname <your@mail.com>'
);

wp_mail( $recipient, $subject, $message, $headers );