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

时间:2021-11-24 15:17:26

I want to send the following fields to wp_mail

我想将以下字段发送到wp_mail

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

If i put all the emails in Email to,Copy to and Bcc to in an array $emails and pass it to wp_mail. How do i set the headers for cc and bcc in wp_mail?

如果我将所有电子邮件放入电子邮件,复制到和密件抄送到数组$ 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 个解决方案

#1


You can use an array to send all the info you need, thus:

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

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

You can get it programmatically, being $copy_to and $bcc_to arrays of said form fields after splitting them by the comma you state in the inner field text, and having defined array $headers:

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

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

#1


You can use an array to send all the info you need, thus:

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

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

You can get it programmatically, being $copy_to and $bcc_to arrays of said form fields after splitting them by the comma you state in the inner field text, and having defined array $headers:

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

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