giozh
giozh

Reputation: 10068

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 <[email protected]>' . "\r\n";
$headers .= "Reply-To: NoReply <[email protected]>\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)?

Upvotes: 0

Views: 1169

Answers (2)

TBI
TBI

Reputation: 2809

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);

Upvotes: 2

Mihai8
Mihai8

Reputation: 3147

In order to use special characters in your script you can try htmlspecialchars function.

Upvotes: 0

Related Questions