yasir ALQAISI
yasir ALQAISI

Reputation: 59

PHPMailer: Subject name in arabic (non-English) characters

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 = "[email protected]";   
$mail->Password = "*******";  
$mail->Port     = "587";  
$mail->From     = "[email protected]";    
$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 = "[email protected]";   
 $mail->Password = "*****";  
 $mail->Port     = "587";  
 $mail->From     = "[email protected]";    
 $mail->FromName = "Enfaltourism";   
 $mail->Subject  = $subject;

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

Upvotes: 2

Views: 8201

Answers (4)

Rene Arteaga
Rene Arteaga

Reputation: 354

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

Upvotes: 0

niczak
niczak

Reputation: 3917

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.

Upvotes: 13

msoa
msoa

Reputation: 1349

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';

Upvotes: 1

Rahul Gupta
Rahul Gupta

Reputation: 10141

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

$phpmailer->Subject = "=?UTF-8?B?".base64_encode($subject)."?=";

Upvotes: 10

Related Questions