How to send UTF-8 email?

When I send an email, characters other than English are not displayed in the email. It shows as below:

ä½ ™ ç "Ya" ä "

Maybe I know what the reason is? Even I tried adding Content-type and charset to the script, it still shows the same thing.

I used Mail::Factory("mail");

+56
php email utf-8
Sep 01 2018-11-11T00:
source share
2 answers

You can add the heading "Content-Type: text / html; charset = UTF-8" to your text.

 $headers = "Content-Type: text/html; charset=UTF-8"; 

If you use native mail() , then the $ headers array function will be the 4th parameter of mail($to, $subject, $message, $headers)

If the user PEAR Mail :: factory () will be:

 $smtp = Mail::factory('smtp', $params); $mail = $smtp->send($to, $headers, $body); 
+80
Sep 01 2018-11-11T00:
source share

I use a fairly specific encoding (ISO-8859-2), because not every mail system (for example: http://10minutemail.com ) can read UTF-8 letters. If you need it:

 function utf8_to_latin2($str) { return iconv ( 'utf-8', 'ISO-8859-2' , $str ); } function my_mail($to,$s,$text,$form, $reply) { mail($to,utf8_to_latin2($s),utf8_to_latin2($text), "From: $form\r\n". "Reply-To: $reply\r\n". "X-Mailer: PHP/" . phpversion()); } 

I made another function of the mailer because the apple device didn’t read the previous version well.

 function utf8mail($to,$s,$body,$from_name="x",$from_a = "info@x.com", $reply="info@x.com") { $s= "=?utf-8?b?".base64_encode($s)."?="; $headers = "MIME-Version: 1.0\r\n"; $headers.= "From: =?utf-8?b?".base64_encode($from_name)."?= <".$from_a.">\r\n"; $headers.= "Content-Type: text/plain;charset=utf-8\r\n"; $headers.= "Reply-To: $reply\r\n"; $headers.= "X-Mailer: PHP/" . phpversion(); mail($to, $s, $body, $headers); } 
+23
Sep 01 2018-11-11T00:
source share



All Articles