Php Mail BCC not working

前端 未结 3 1550
予麋鹿
予麋鹿 2021-01-24 10:24

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

$to = $your_email;
$from = \"Server Xt\";
$subject = \"User Sent M         


        
相关标签:
3条回答
  • 2021-01-24 10:31

    Separate headers by \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");  
       }  
    }
    
    0 讨论(0)
  • 2021-01-24 10:34

    it looks the order of header is important!!!

    $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";
    
    0 讨论(0)
  • 2021-01-24 10:35

    Is $headers .= "Bcc:email@example.com"\n" the exact syntax that you are using?

    You should be receiving an error if so as that isn't valid PHP syntax.

    Try changing to something like $headers .= 'Bcc:email@example.com' . "\r\n";

    0 讨论(0)
提交回复
热议问题