简体   繁体   English

PHP邮件添加密件抄送

[英]PHP Mail adding BCC

I have a form that populates a PHP mail to be sent to our clients, I want to BCC most of the clients due to privacy. 我有一个填写要发送给我们客户的PHP邮件的表格,由于隐私原因,我想对大多数客户进行密件抄送。 I have the following code 我有以下代码

$to = "******@e-track.co.za"; //To recipients 
$email_from = '*****@etrackbureau.co.za';//<== update the email address
$email_subject = "New Overdue Loaded";
$email_body = "A new High Risk Client has been loaded by $name $company.\n".
    "\n Client Name: $driver_name $driver_surname\n
    \n Client ID or Passport Number: $driver_id\n
    \n Nationality: $driver_nationality\n
    \n Reason for Loading Client: $type\n
    \n Notes: $notes\n
    ".
$headers = "From: $email_from \r\n";
$headers = "Bcc: ******@e-track.co.za;*****@e-track.co.za;******@e-track.co.za\r\n";
//$headers = "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);

I have added the BCC as a $headers but once I add this it doesn't send mails at all when I remove it I get the mail to the $to recipient. 我已经将密件抄送添加为$ headers,但是一旦添加了它,它在删除后根本不会发送邮件,而是将邮件发送到$ to收件人。

I have tried spacing between the BCC mails as well. 我也尝试了密件抄送邮件之间的间隔。 I have replaced the mail names with **** for spamming reasons 由于垃圾邮件的原因,我用****替换了邮件名

You should concatenate $headers 您应该连接$headers

Example : 范例:

$headers  = "From: *****@etrackbureau.co.za\r\nX-Mailer: php\r\n";
$headers .= "MIME-Version: 1.0\r\n"; #Define MIME Version
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; #Set content type
$headers .= "Bcc: $EmailListHere\r\n"; #Your BCC Mail List

You need to concatenate the header strings. 您需要串联标题字符串。 Replace 'header =' by 'header .=' in your code 在代码中将“ header =”替换为“ header。=”

// Additional headers //其他标题

$headers[] = 'To: Mary <mary@example.com>, Kelly <kelly@example.com>';
$headers[] = 'From: Birthday Reminder <birthday@example.com>';
$headers[] = 'Cc: birthdayarchive@example.com';
$headers[] = 'Bcc: birthdaycheck@example.com';

// Mail it //邮寄

mail($to, $subject, $message, implode("\r\n", $headers));

link 链接

if you are using phpMailer you should use 如果您使用的是phpMailer,则应使用

$mail->addBCC('bcc@example.com');

this will do the trick and where ur using 这将解决问题,您在哪里使用

$headers = "Bcc: ******@e-track.co.za;*****@e-track.co.za;******@e-track.co.za\r\n";

concatenate it dont use = as it will over write the previous $headers variable 连接它不要使用=,因为它将覆盖先前的$headers变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM