简体   繁体   中英

send html email with php contains special characters

i need to send php email with html and special characters like è, à, ò .." and i've write this:

$message = "
        <html>
            <head>
            <title>TITLE</title>
            </head>
            <body>
              &#224 &#232
            </body>
        </html>";

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html;  charset=UTF-8' . "\r\n";
$headers .= 'From: NoReply <noreply@asd.com>' . "\r\n";
$headers .= "Reply-To: NoReply <noreply@asd.com>\r\n";
mail($email, $subject, $message, $headers);

Now, when i launch my script, on gmail preview of received email is correct (letters are showed correctly), but when i open email, i see " &#224 &#232", not the relative special character. How can i solve it (without using external libraries)?

Use utf8_decode() function for $message.

$message = "<html>
               <head>
                   <title>TITLE</title>
               </head>
               <body>
                  &#224; &#232;
               </body>
            </html>";

mail($email, $subject, utf8_decode($message), $headers);

为了在脚本中使用特殊字符,您可以尝试htmlspecialchars函数。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM