Search code examples
phpemailcharactercontent-typemime

PHP: How to include special characters with mail()?


I am trying to send a HTML mail using PHP's mail() function but some of our special Danish characters are completely messed up for the receiver.

The actual mail starts with this:

<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
<title>My Title</title>
</head>

And I have the headers setup like this:

$headers  = "From: My Company <info@mydomain.com>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

But characters such as Æ,Ø and Å are being replaced by weird characters (e.g. the word PÅ is now written as PÃ¥).


Solution

  • Try utf-8 encoding in header

    like,

    $headers .= "Content-Type: text/html; charset=utf-8\r\n";
    

    See this How to convert these strange characters? (ë, Ã, ì, ù, Ã)