使用wp_mail发送带有密件抄送和密件的电子邮件

时间:2015-05-07 10:39:19

标签: wordpress

我想将以下字段发送到wp_mail

enter image description here

如果我将Email toCopy toBcc to中的所有电子邮件放入数组$emails并将其传递给wp_mail。如何在wp_mail中设置cc和bcc的标题?

$headers = 'From: Test <info@test.co.uk>' . '\r\n';
$headers.= 'Content-type: text/html\r\n'; 
$success = wp_mail( $emails, $subject, $message, $headers );  

1 个答案:

答案 0 :(得分:9)

您可以使用数组发送所需的所有信息,因此:

$headers[] = 'From: Test <info@test.co.uk>';
$headers[] = 'Cc: copy_to_1@email.com';
$headers[] = 'Cc: copy_to_2@email.com';
...
$headers[] = 'Bcc: bcc_to_1@email.com';
$headers[] = 'Bcc: bcc_to_2@email.com';
$success = wp_mail( $emails, $subject, $message, $headers );  

您可以通过编程方式获取它,在使用您在内部字段文本中声明的逗号分隔它们并且已定义数组$copy_to之后,将所述表单字段的$bcc_to$headers数组:

$headers[] = 'From: Test <info@test.co.uk>';
foreach($copy_to as $email){
    $headers[] = 'Cc: '.$email;
}
foreach($bcc_to as $email){
    $headers[] = 'Bcc: '.$email;
}
$success = wp_mail( $emails, $subject, $message, $headers );