1

I am trying to edit this script to send a Bcc copy to myself:

$to = $your_email;
$from = "Server Xt<dml_submitbot@noemail.com>";
$subject = "User Sent Msg :: $msg";
$HTMLmessage = $message;

emailHTML($to, $from, $subject, $HTMLmessage);

function emailHTML($to, $from, $subject, $HTMLmessage){

   $semi_rand = md5(time());  
   $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";  

   $headers = "From: ".$from;      
   $headers .=
   "\nMIME-Version: 1.0\n" .  
   "Content-Type: multipart/mixed;\n" .  
   " boundary=\"{$mime_boundary}\"";  

   $content .=
   "This is a multi-part message in MIME format.\n\n" .  
   "--{$mime_boundary}\n" .  
   "Content-Type:text/html; charset=\"iso-8859-1\"\n" .  
   "Content-Transfer-Encoding: 7bit\n\n" .  
   $HTMLmessage . "\n\n";  

   $ok = @mail($to, $subject, $content, $headers);  

   if(!$ok) {    
   die("Error sending email");  
   }  
}

i have tried to add this $headers .= "Bcc:email@example.com"\n"; but it does not send out the email... How do I go about modofying this script to make it work?

4

3 回答 3

3

用 分隔标题\r\n

function emailHTML($to, $from, $subject, $HTMLmessage) {

   $semi_rand = md5(time());  
   $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";  

   $headers = "From: ".$from . "\r\n";   
   $headers .= "Bcc: email@example.com\r\n";   
   $headers .=
   "MIME-Version: 1.0\r\n" .  
   "Content-Type: multipart/mixed;\r\n" .  
   " boundary=\"{$mime_boundary}\"";  

   $content .=
   "This is a multi-part message in MIME format.\r\n\r\n" .  
   "--{$mime_boundary}\r\n" .  
   "Content-Type:text/html; charset=\"iso-8859-1\"\r\n" .  
   "Content-Transfer-Encoding: 7bit\r\n\r\n" .  
   $HTMLmessage . "\r\n\r\n";  

   $ok = @mail($to, $subject, $content, $headers);  

   if(!$ok) {    
   die("Error sending email");  
   }  
}
于 2014-01-19T09:15:00.650 回答
1

看起来标题的顺序很重要!!!

$from = "Sender Name<sender@stackoverflow.com>";
$to="receiver@stackoverflow.com";
$headers = "From: $from\r\n";
$headers .= "To: $to\r\n";
$headers .= "Return-Path: <".$to.">\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Bcc:email@gmail.com\r\n";
$headers .= "Content-Type: text/HTML; charset=ISO-8859-1\r\n";
于 2016-05-25T19:44:53.400 回答
0

$headers .= "Bcc:email@example.com"\n"您使用的确切语法吗?

如果这不是有效的 PHP 语法,您应该会收到错误消息。

尝试更改为类似$headers .= 'Bcc:email@example.com' . "\r\n";

于 2014-01-19T09:13:27.967 回答