Welcome Guest, Not a member yet? Register   Sign In
Encoding email subject for foreign languages
#1

[eluser]sehummel[/eluser]
I have an email function that is set up to send out an email when a user wants to contact us. I have figured out how to send the body of the email in the foreign language by using HTML, but I understand the subject line can only handle ASCII characters. What workaround is there so I can send the subject line in say Korean or Chinese? Is there a limitation in CI that's going to force me to use some regular PHP to do this?
#2

[eluser]Nick_MyShuitings[/eluser]
example code pls? or else there is not much to do to help troubleshoot this.
#3

[eluser]InsiteFX[/eluser]
Try reading this:

RFC 2047 - MIME (Multipurpose Internet Mail Extensions)

InsiteFX
#4

[eluser]sehummel[/eluser]
I found this example online, but it doesn't work.

Code:
$charset = "GB2312";
$to = 'my email address';
$subject = '标有星号 (*) 的字段为必填项。';
//this is the encoded subject;
$encoded_subject = "=?$charset?B?".base64_encode($subject)."?=\n" ;
$message = 'some chinese text';

//HEADERS
$header = "X-Mailer: Whatever you want\n";
$header .= "Return-Path: <[email protected]>\n";
$header .= "MIME-Version: 1.0\n";
$header .= "From: Some Person <[email protected]>\n";

//I believe that language code for chinese is cn
$header .= "X-Accept-Language: cn\n";

//This header should make sure that the message has a Guobiao
//encoding
$header .= "Content-Type: text/html; charset={$charset}\n";

//I'm not an expert, but depending on the character set you use
//you may want to change the transfer encoding.
//I found that GB2312 is 7 bit, so I believe you can
//leave this header out. If you choose another encoding
//make sure the transfer encoding is correct.
//$header .= "Content-Transfer-Encoding: 8bit\n";

//Print error if mail doesn't work, otherwise print successful message
if(!mail($to, $encoded_subject, $message, $header)) {
echo "Error: Message not sent";
}
else {
echo "Message sent successfully!";

Can you help me debug this?
#5

[eluser]sehummel[/eluser]
I found the answer. In the script, define $encoded_subject as
Code:
mb_encode_mimeheader($subject, 'UTF-8);
and it works
#6

[eluser]smartweb[/eluser]
UTF8 is the best way




Theme © iAndrew 2016 - Forum software by © MyBB