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

2022-08-31 00:33:35

我想将以下字段发送给wp_mail

enter image description here

如果我把所有的电子邮件都放在一个数组中,然后传递给wp_mail。如何在wp_mail中设置cc和bcc的标题?Email toCopy toBcc to$emails

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

答案 1

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

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

答案 2

推荐