使用密件抄送和cc用wp_mail发送电子邮件 [英] Sending emails with bcc and cc with wp_mail

查看:102
本文介绍了使用密件抄送和cc用wp_mail发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将以下字段发送到wp_mail

I want to send the following fields to wp_mail

如果我将所有电子邮件放在数组$emails中的Email toCopy toBcc to中,并将其传递给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?

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

推荐答案

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

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

您可以通过编程的方式获得它,即将所述表单字段的$copy_to$bcc_to数组按内部字段文本中的逗号分隔并定义了数组$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[] = '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 );  

这篇关于使用密件抄送和cc用wp_mail发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆