note 69830 deleted from function.mail by bobby
| From: | bobby@php.net | Date: | Tue, 10 Oct 2006 20:54:57 +0000 |
| Subject: | note 69830 deleted from function.mail by bobby | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-118370@lists.php.net to get a copy of this message | ||
Note Submitter: marcelo dot maraboli at usm dot cl
----
If you want to send accents (or special characters) in the subject, you must encode the string to a
ISO-8859-1 format before sending the email. It is not enough just to add the Content-type header,
because that's for encoding the content, not encoding the headers.
Use this funtion:
function encode_iso88591($string)
{
$text = '=?iso-8859-1?q?';
for( $i = 0 ; $i < strlen($string) ; $i++ )
{
$val = ord($string[$i]);
if($val > 127)
{
$val = dechex($val);
$text .= '='.$val;
}
else
{
$text .= $string[$i];
}
}
$text .= '?=';
return $text;
}
and later use:
// create email
$msg = wordwrap($msg, 70);
$to = "destination@company.com";
$subject = encode_iso88591("hoydÃa caminé !!");
$headers = "MIME-Versin: 1.0\r\n" .
"Content-type: text/plain; charset=ISO-8859-1; format=flowed\r\n" .
"Content-Transfer-Encoding: 8bit\r\n" .
"From: $from\r\n" .
"X-Mailer: PHP" . phpversion();
mail($to, $subject, $msg, $headers);