sending japanese email
Posted: Fri Oct 22, 2004 10:15 am
Greetings, developers.
My first post here is regarding sending a japanese email - I would be very grateful for your knowledge/advice.
I have a script to encode the mail properly in unicode (UTF-8), and when I use outlook to receive the email, it comes through fine. The problem occurs when it is picked up through Entourage on a Mac, or Lotus Notes - the encoding is "Automatic" and not on UTF-8, so it has to be set manually.
The mail will be sent to Japanese machines, so they will need to read it with UTF-8 encoding.
I had thought by setting the header to UTF-8, it would automatically set the encoding on the email program to UTF-8, but this does not seem to be the case.
Does anyone have any advice on this?
Here is my script:
Many thanks,
Dan
My first post here is regarding sending a japanese email - I would be very grateful for your knowledge/advice.
I have a script to encode the mail properly in unicode (UTF-8), and when I use outlook to receive the email, it comes through fine. The problem occurs when it is picked up through Entourage on a Mac, or Lotus Notes - the encoding is "Automatic" and not on UTF-8, so it has to be set manually.
The mail will be sent to Japanese machines, so they will need to read it with UTF-8 encoding.
I had thought by setting the header to UTF-8, it would automatically set the encoding on the email program to UTF-8, but this does not seem to be the case.
Does anyone have any advice on this?
Here is my script:
Code: Select all
<?php
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=UTF-8\\n";
/* turn all line breaks into BR tags */
$body = nl2br($body);
}
else {
$headers .= "Content-Type: text/plain;charset=UTF-8\\n";
}
/* need to convert body to same encoding as stated in Content-Type header above */
$body = mb_convert_encoding($body, "UTF-8","UTF-8");
/* 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("uni");
$subject = mb_convert_encoding($subject, "UTF-8","UTF-8");
$subject = mb_encode_mimeheader($subject);
mail($to, $subject, $body, $headers, $sendmail_params) or die("could not send email");
}
$to = name@domain.com";
$subject = "japanese character test";
// japanese text in here
$body = "試してみてください";
$from = "name";
$from_email = "name@domain.com";
$is_html_content = false;
send_japanese_mail($to, $subject, $body, $from, $from_email, $is_html_content);
?>Many thanks,
Dan