Sending Japanese Emails in ISO‑2022‑JP or UTF‑8 with PHP
You can send Japanese emails using the mb_send_mail function, but by default the message is typically sent in ISO‑2022‑JP (JIS).
By configuring the mb_language function, you can send emails using the UTF‑8 character encoding instead.
Sending Japanese Emails in UTF‑8
The following source code sends a Japanese email encoded in UTF‑8 using Base64 encoding.
<?php
mb_language('uni');
$to = "to@hoge.co.jp"; //Recipient
$sub = "メール件名";
$body = "メール本文\r\n本文2行目\r\n本文3行目";
//Email header settings
$hd = "From: from@hoge.co.jp\r\n". // The From header is required
"Cc: cc<cc@hoge.co.jp>\r\n".
"Bcc: bcc<bcc@hoge.co.jp>\r\n".
"Reply-To: from@hoge.co.jp\r\n".
"X-Mailer: PHP/" . phpversion();
mb_send_mail($to, $sub, $body, $hd);
?>
Sending Japanese Emails in ISO‑2022‑JP (JIS)
The following source code sends a Japanese email encoded in ISO‑2022‑JP (JIS).
<?php
mb_language('Japanese');
$to = "to@hoge.co.jp"; //Recipient
$sub = "メール件名";
$body = "メール本文\r\n本文2行目\r\n本文3行目";
//メールヘッダーの設定
$hd = "From: from@hoge.co.jp\r\n". // The From header is required
"Cc: cc<cc@hoge.co.jp>\r\n".
"Bcc: bcc<bcc@hoge.co.jp>\r\n".
"Reply-To: from@hoge.co.jp\r\n".
"X-Mailer: PHP/" . phpversion();
mb_send_mail($to, $sub, $body, $hd);
?>
