note 29174 added to function.mb-send-mail
| From: | jc at rack1 dot php dot net | Date: | Wed, 05 Feb 2003 06:58:38 +0000 |
| Subject: | note 29174 added to function.mb-send-mail | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-43441@lists.php.net to get a copy of this message | ||
I was trying to send japanese email and had a hell of a time getting it to work. I finally stumbled
across mb_send_mail() and it did everything I wanted *except* that it only send plain text emails
... sending HTML contents was impossible.
I finally whipped this up. I'm posting in case someone finds it useful.
function send_japanese_mail($to, $subject, $body, $from, $from_email, $is_html_content=false) {
$headers = "MIME-Version: 1.0\\n" ;
$headers .= "From: $from <$from_email>\\n";
$headers .= "Reply-To: $from <$from_email>\\n";
/* If the body is HTML or plain text set the Content-Type header accordingly */
if ($is_html_content) {
$headers .= "Content-Type: text/html;charset=ISO-2022-JP\\n";
/* turn all line breaks into BR tags */
$body = nl2br($body);
}
else {
$headers .= "Content-Type: text/plain;charset=ISO-2022-JP\\n";
}
/* need to convert body to same encoding as stated in Content-Type header above */
$body = mb_convert_encoding($body, "ISO-2022-JP","AUTO");
/* set any sendmail params, optional ... */
$sendmail_params = "-f$from_email";
/*
The subject is actually a "header" and can/will get mangled
if it contains non-ASCII characters. So we need to convert
the subject to something containing only ASCII characters.
First we convert the subject to the same encoding as the
body, then we use mb_encode_mimeheader() to make the subject
line all ASCII characters.
*/
mb_language("ja");
$subject = mb_convert_encoding($subject, "ISO-2022-JP","AUTO");
$subject = mb_encode_mimeheader($subject);
mail($to, $subject, $body, $headers, $sendmail_params);
}
--
http://www.php.net/manual/en/function.mb-send-mail.php
http://master.php.net/manage/user-notes.php?action=edit+29174
http://master.php.net/manage/user-notes.php?action=delete+29174
http://master.php.net/manage/user-notes.php?action=reject+29174