PHP mail special characters in subject field

后端 未结 3 1678
粉色の甜心
粉色の甜心 2020-12-31 03:26

I would like to insert special characters in the subject of HTML e-mails sent with the PHP mail() function.

I want my subject to look like this:

★ Yo

3条回答
  •  时光说笑
    2020-12-31 04:25

     $headers="";    
     $message = utf8_encode($message);
     $message = wordwrap($message, 70, "\r\n");
     $subject = '=?UTF-8?B?'.base64_encode(utf8_encode($subject)).'?=';
     $to_name = '=?UTF-8?B?'.base64_encode(utf8_encode($to_name)).'?=';
     $from_name = '=?UTF-8?B?'.base64_encode(utf8_encode($from_name)).'?=';
    
     $headers .= "MIME-Version: 1.0" . "\r\n"; 
     $headers .= "Content-type: text/plain; charset=utf-8" . "\r\n"; 
     //$headers .= "Content-Transfer-Encoding: quoted-printable" . "\r\n"; 
     $headers .= "From: $from_name <$from_email>" . "\r\n"; 
     $headers .= "To: $to_name <$to_email>" . "\r\n";
     $headers .= "Subject: $subject" . "\r\n";
     $headers .= "X-Mailer: PHP/" . phpversion();  
    
     mail("", $subject, $message, $headers); 
    

提交回复
热议问题