wordpress 在wp_mail头中设置回复地址

u4dcyp6a  于 2023-08-03  发布在  WordPress
关注(0)|答案(2)|浏览(132)

我使用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 );

字符串

xpcnnkqh

xpcnnkqh1#

您可以在$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 );

字符串

bnl4lu3b

bnl4lu3b2#

下面是一个完整的例子,包括标题和附件。

$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);

字符串

相关问题