note 27997 added to function.mail
| From: | gordon at kanazawa-gu dot ac dot jp | Date: | Sun, 29 Dec 2002 00:04:33 +0000 |
| Subject: | note 27997 added to function.mail | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-41403@lists.php.net to get a copy of this message | ||
If your server doesn't have mb_send_mail() enabled but you want to use non-ascii (multi-byte)
chars in an email's subject or name headers, you can use something like the following:
$charset = "iso-2202-jp"; // japanese
$to = encode("japanese name 01", $charset) . " <to@email.com>";
$from = encode("japanese name 02", $charset) . " <from@email.com>";
$subject = encode("japanese text");
$message = "does not need to be encoded";
mail($to, $subject, $message, $from);
function encode($in_str, $charset) {
$out_str = $in_str;
if ($out_str && $charset) {
// define start delimimter, end delimiter and spacer
$end = "?=";
$start = "=?" . $charset . "?B?";
$spacer = $end . "\r\n " . $start;
// determine length of encoded text within chunks
// and ensure length is even
$length = 75 - strlen($start) - strlen($end);
$length = floor($length/2) * 2;
// encode the string and split it into chunks
// with spacers after each chunk
$out_str = base64_encode($out_str);
$out_str = chunk_split($out_str, $length, $spacer);
// remove trailing spacer and
// add start and end delimiters
$spacer = preg_quote($spacer);
$out_str = preg_replace("/" . $spacer . "$/", "", $out_str);
$out_str = $start . $out_str . $end;
}
return $out_str;
}
// for details on Message Header Extensions
// for Non-ASCII Text see ...
// http://www.faqs.org/rfcs/rfc2047.html
--
http://www.php.net/manual/en/function.mail.php
http://master.php.net/manage/user-notes.php?action=edit+27997
http://master.php.net/manage/user-notes.php?action=delete+27997
http://master.php.net/manage/user-notes.php?action=reject+27997