PHP 电子邮件发送密件抄送
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9525415/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP Email sending BCC
提问by glln
I know there are a few similar questions to this but I just can't get it working.
我知道有一些类似的问题,但我无法让它工作。
Ok, I have a list of emails grabbed from my database in a variable called $emailList.
I can get my code to send an email from a form if I put the variable in the $to
section but
I cannot get it to work with bcc. I've even added an email to the $to
incase it was that but it doesn't make a difference.
好的,我在一个名为 $emailList 的变量中从我的数据库中获取了一个电子邮件列表。如果我将变量放在该$to
部分,我可以让我的代码从表单发送电子邮件,但我无法让它与 bcc 一起使用。我什至添加了一封电子邮件,$to
以防万一,但这并没有什么区别。
Here is my code.
这是我的代码。
$to = "[email protected]";
$subject .= "".$emailSubject."";
$headers .= 'Bcc: $emailList';
$headers = "From: [email protected]\r\n" . "X-Mailer: php";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= 'THE MESSAGE FROM THE FORM';
if (mail($to, $subject, $message, $headers)) {
$sent = "Your email was sent!";
} else {
$sent = ("Error sending email.");
}
I've tried both codes:
我已经尝试了两种代码:
$headers .= 'Bcc: $emailList';
and
和
$headers .= 'Bcc: '.$emailList.';
It's not that the emails aren't separated because they are. I know they are because it works if I put $emailList
in the $to
section.
并不是说电子邮件没有分开,因为它们是分开的。我知道它们是因为如果我放入$emailList
该$to
部分它会起作用。
I Should add, ignore the $message
bits and the HTML stuff. I've not provided all of that so that is why it's missing from this code.
我应该补充一点,忽略这些$message
位和 HTML 内容。我没有提供所有这些,所以这就是代码中缺少它的原因。
回答by gregheo
You have $headers .= '...';
followed by $headers = '...';
; the second line is overwriting the first.
您已$headers .= '...';
关注$headers = '...';
;第二行覆盖第一行。
Just put the $headers .= "Bcc: $emailList\r\n";
say after the Content-type
line and it should be fine.
只需在行$headers .= "Bcc: $emailList\r\n";
后加上sayContent-type
就可以了。
On a side note, the To
is generally required; mail servers might mark your message as spam otherwise.
附带说明一下,To
通常需要 ; 否则邮件服务器可能会将您的邮件标记为垃圾邮件。
$headers = "From: [email protected]\r\n" .
"X-Mailer: php\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "Bcc: $emailList\r\n";
回答by Bot
You were setting BCC but then overwriting the variable with the FROM
您正在设置 BCC,但随后使用 FROM 覆盖变量
$to = "[email protected]";
$subject .= "".$emailSubject."";
$headers .= "Bcc: ".$emailList."\r\n";
$headers .= "From: [email protected]\r\n" .
"X-Mailer: php";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= 'THE MESSAGE FROM THE FORM';
if (mail($to, $subject, $message, $headers)) {
$sent = "Your email was sent!";
} else {
$sent = ("Error sending email.");
}