2

I am using PHPMailer API for sending emails. I was wondering how can I send the subject in Arabic (non-English) language

$mail->CharSet  =  'utf-8';
$array=  FetchTable('cos');
$subject =  $_POST['subject'];
$body    =  $_POST['body'];

$mail = new PHPMailer();
$mail->IsSMTP();    
$mail->Host     = "host";    
$mail->SMTPAuth = true;    
$mail->Username = "yaz@enfaltourism.com";   
$mail->Password = "*******";  
$mail->Port     = "587";  
$mail->From     = "yaz@enfaltourism.com";    
$mail->FromName = "Enfaltourism";   
$mail->Subject  = $subject;     
$mail->AddAddress($email); 
$mail->Send();`

The email is being successfully sent, but the problem is in sending subject in Arabic language. The email message body is displayed properly in Arabic after I set the char encoding but the the subject is being displayed in weird characters

Update

include("../mail/class.phpmailer.php");
$array=  FetchTable('cos');
$subject =  $_POST['subject'];
$body    =  $_POST['body'];
    $mail = new PHPMailer();
    $mail->CharSet  =  'utf-8';
    $mail->IsSMTP();    
 $mail->Host     = "mail.enfaltourism.com";    
 $mail->SMTPAuth = true;    
 $mail->Username = "yaz@enfaltourism.com";   
 $mail->Password = "*****";  
 $mail->Port     = "587";  
 $mail->From     = "yaz@enfaltourism.com";    
 $mail->FromName = "Enfaltourism";   
 $mail->Subject  = $subject;

i fixed as u told but the subject still weird character like this

Rahul Gupta
  • 9,775
  • 7
  • 56
  • 69
yasir ALQAISI
  • 59
  • 1
  • 8

4 Answers4

13

I had this same problem with Japanese characters, both in the body and in the subject line:

I resolved it (email looks outstanding now) by doing:

$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';

There really isn't any need to encode the subject separately so long as the object has the CharSet property set to UTF-8.

Legionar
  • 7,472
  • 2
  • 41
  • 70
niczak
  • 3,897
  • 11
  • 45
  • 65
10

you can try using this code. Let me know if it helps

$phpmailer->Subject = "=?UTF-8?B?".base64_encode($subject)."?=";
Rahul Gupta
  • 9,775
  • 7
  • 56
  • 69
1

Try encoding subject with base64_encode

$subject = '=?UTF-8?B?'.base64_encode('سلام علیکم').'?=';

However with setting the issue must be solved.

$mail = new PHPMailer;
$mail->CharSet = 'UTF-8';
msoa
  • 1,339
  • 3
  • 14
  • 33
0

Try this:

$mail->CharSet = 'UTF-8';
$mail->Subject = html_entity_decode("Recuperación de contraseña");

I did use this in my code and it worked!

Results

Tom Aranda
  • 5,919
  • 11
  • 35
  • 51
Rene Arteaga
  • 334
  • 3
  • 6