想在邮件上发送阿拉伯语html内容
我试过了
require_once "Mail.php";
require_once "Mail/mime.php";
// see http://pear.php.net/manual/en/package.mail.mail-mime.php
// for further extended documentation on Mail_Mime
mb_internal_encoding("UTF-8");
$from = "test@from.com";
$to = "test@from.com"
$subject = "Test HTML email using PHP Pear w/ SMTP\r\n\r\n";
$text = "This is a text test email message";
$html = "<meta charset='utf-8' /><html><body> حتى لو أقيمت الولائم السياسية كل يوم! على الرغم من نجاح أنصار مشروع الصوت الواحد في التحكم في الأمر الواقع بعد فرض تطبيق المشروع، وعجز المعارضة عن تغيير هذا الواقع، إلا أن المريح في الأمر أن المشروع السياسي المصاحب "للصوت الواحد" مازال بلا جذور، أي مازال مشروعا فطريا يمكن تغييره في لحظة ومن دون مجهود كبير. وهو مشروع شخصي لا صلة له بفكرة الدولة وأصول إدارة شؤونها، وهو أيضا ناتج عن دوافع</body></html>";
$crlf = "\n";
// create a new Mail_Mime for use
$mime = new Mail_mime($crlf);
// define body for Text only receipt
$mime->setTXTBody($text);
// define body for HTML capable recipients
$mime->setHTMLBody($html);
// specify a file to attach below, relative to the script's location
// if not using an attachment, comment these lines out
// set appropriate MIME type for attachment you are using below, if applicable
// for reference see http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
$file = "attachment.jpg";
$mimetype = "image/jpeg";
$mime->addAttachment($file, $mimetype);
// specify the SMTP server credentials to be used for delivery
// if using a third party mail service, be sure to use their hostname
$host = "*******";
$username = "************";
$password = "*******";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject,
'Content-Type' => 'text/html; charset=UTF-8');
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$body = $mime->get();
$headers = $mime->headers($headers);
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
//echo(" " . $mail->getMessage() . " ");
echo 1;
} else {
//echo(" Message successfully sent! ");
echo 2;
}
?>
但在邮件中获取的数据如下:
لقد تغيرت طبيعة العلاقة بين أسرة آل ØµØ¨Ø§Ø ÙˆØ§Ù„Ø´Ø¹Ø¨ØŒ ولن تعود إلى ما كانت عليه Øتى لو أقيمت "الولائم السياسية" كل يوم!
那么这里要做什么?
请帮帮我
最佳答案
你可以使用PHPMailer Class
它功能强大,而且是开源的。 要获取示例,请阅读此 PHPMailer class examples
阿拉伯语、波斯语等的例子
<?php
require_once('class.phpmailer.php');
$mail = new PHPMailer(true);
$mail->IsSMTP();
try {
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->Username = "yourname@gmail.com";
$mail->Password = "************";
$mail->AddReplyTo('yourname@example.com', 'Your Name');
$mail->AddAddress('username@example.com', 'User Name');
$mail->SetFrom('yourname@example.com', 'Your Name'); //
$mail->Subject = 'موضوع';
$mail->AltBody = 'برنامه شما از این ایمیل پشتیبانی نمی کند، برای دیدن آن، لطفا از برنامه دیگری استفاده نمائید'; // متنی برای کاربرانی که نمی توانند ایمیل را به درستی مشاهده کنند
$mail->CharSet = 'UTF-8';
$mail->ContentType = 'text/html';
$mail->MsgHTML('<html>
<body>
این یک <font color="#CC0000">تست</font> است!
</body>
</html>'); // متن پیام به صورت html
//$mail->AddAttachment('images/phpmailer.gif'); // ضمیمه کردن فایل
$mail->Send();
echo "پیام با موفقیت ارسال شد\n";
}
catch (phpmailerException $e) {
echo $e->errorMessage();
}
catch (Exception $e) {
echo $e->getMessage();
}
?>
关于php - 如何在 php smtp 中发送带有阿拉伯语 html 内容的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22093643/