gpt4 book ai didi

php - 使用密件抄送和使用 wp_mail 抄送发送电子邮件

转载 作者:行者123 更新时间:2023-12-03 03:20:42 25 4
gpt4 key购买 nike

我想将以下字段发送到 wp_mail

enter image description here

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

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

最佳答案

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

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

这些之所以有效,是因为 wp_mail() 不信任您,因此会正确规范并连接多个 Cc:Bcc: header 。 The RFC spec要求这些 header 仅出现一次,多个收件人以逗号分隔,如果行太长则“折叠”,因此它无法在纯 PHP 中工作。

关于php - 使用密件抄送和使用 wp_mail 抄送发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30098670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com