i want to send message of this email in utf8 coding ..
what can i do for this
include 'functions.php';
$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
$subject = stripslashes($_POST['subject']);
$message = stripslashes($_POST['message']);
$cap=strtoupper($_POST['cap']);
$error = '';
$mail = mail(WEBMASTER_EMAIL,$subject,$message,
"From: ".$name." <".$email.">\r\n"
."Reply-To: ".$email."\r\n"
."X-Mailer: PHP/" . phpversion());
what can i send this in utf8 ?
You can specify the encoding in the email headers, like so:
$mail = mail(WEBMASTER_EMAIL,$subject,$message,
"From: ".$name." <".$email.">\r\n"
."Reply-To: ".$email."\r\n"
."Content-type: text/html; charset=UTF-8\r\n"
."X-Mailer: PHP/" . phpversion());
You can use php's utf8_encode function. Like so:
$message = utf8_encode(stripslashes($_POST['message']));
This will store the string utf8 encoded in your $message variable or any other for that matter.
Edit:
If you use the swiftmailer library, it will default to utf8 encoding.
You need to set the utf-8 encoding in the headers and also encode the subject, because it easily gets corrupted. I personally create my own function which also adds the ability to set the sender's adress:
function mail_utf8 ($to, $subject='', $message='', $from='', $header='') {
if (preg_match("/\<html.*\>/i", $message))
$content_type = "html";
else
$content_type = "plain";
$header .= "\nMIME-Version: 1.0";
$header .= "\nContent-type: text/$content_type; charset=UTF-8";
if ($from)
$header .= "\nFrom: ".$from;
mail($to, "=?UTF-8?B?".base64_encode($subject)."?=", $message, trim($header));
}
来源:https://stackoverflow.com/questions/13732253/how-to-send-an-email-in-utf8