在 wp_mail 头部设置回复地址

7
我使用wp_mail在我的WordPress主题中发送通知。如何在以下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 );     

   
2个回答

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

$headers[] = '回复至: 名字 姓氏 <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 );

0
这是一个包含标题和附件的完整示例。
$from_name = 'name';
$from = 'from@example.test';
$subject = 'test';    
$body = 'Test';
$to = 'test@example.test';
$bcc = 'bccemail@example.text';
$attachments[] = WP_CONTENT_DIR.'/uploads/'.$path_to_file;
$headers[] = 'Content-Type: text/html; charset=UTF-8';
$headers[] = 'From: '.$from_name.' <'.$from.'>';
$headers[] = 'Reply-To: '.$from_name.' <'.$from.'>';
//add BCC if want 
$headers[] = 'Bcc: '.$bcc;

$success = wp_mail($to, $subject, $body, $headers, $attachments);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接