Question

Want to send arabic html content on mail

I Tried

 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;
}
?>

but in mail getting data like:

لقد تغيرت طبيعة العلاقة بين أسرة آل صباح والشعب، ولن تعود إلى ما كانت عليه حتى لو أقيمت "الولائم السياسية" كل يوم!

so waht to do here?

Please help me

Was it helpful?

Solution

you can use PHPMailer Class

it is powerful , and open source . for get examples please read this PHPMailer class examples

example for arabic , persian and etc.

<?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();
}
?>

OTHER TIPS

For Arabic and other non-ascii characters, you need to specify an extended character set, such as UTF-8.

In the header of the MIME section of the email that contains the Arabic characters, add one of the following lines (depending on whether the MIME section is plain text or HTML), and that should solve the problem:

Content-Type: text/html; charset=UTF-8
Content-Type: text/plain; charset=UTF-8
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top