4

I am using PHPMailer and trying to send email with the Arabic text, It's sending the Empty Subject , I can see in my Inbox "(no subject)"

I am using following :

HTML code

<form action="mail.php" method="post">
<input type="text" name="subject" />
<input type="submit" value="Send" />
</form>

PHP Code (mail.php)

$subject = $_POST["subject"];
    $mailer = new PHPMailer();
            $mailer->CharSet = 'UTF-8';
            $mailer->IsSMTP();
            $mailer->SMTPDebug = 1;
            $mailer->SMTPAuth = true;



            // Prepare Message  
            $mailer->Subject = ($subject);
            $emails = 0;

Help will be appreciated :)

Shahzab Asif
  • 481
  • 5
  • 13

6 Answers6

11

just add

$mailer->CharSet = 'UTF-8';

and its works

Niki van Stein
  • 10,564
  • 3
  • 29
  • 62
Ehsan KHAN
  • 141
  • 1
  • 6
4

use this. its worked for me.

    $mail = new PHPMailer();
    $mail->CharSet = 'UTF-8';       
    $mail->IsSMTP();                                   // send via SMTP
    $mail->Encoding     = "base64";
    $mail->Host     = ........

    ...

    $mail->Subject  =  '=?UTF-8?B?'.base64_encode($subject).'?=';

if you have htmlentities ($subject) change it to htmlspecialchars ($subject) htmlenitities breaks encoding.

ewroman
  • 625
  • 6
  • 14
1

Try the following steps to address the problem correctly.

  1. Make sure the page that's posting the subject is a UTF-8 encoded page.

    1a. If the source isn't UTF-8, then

    iconv("SOURCE_ENCODING","UTF-8",$subject);
    
  2. Var Dump the subject before sending the mail.

  3. Try to add a hard-coded subject in Arabic, e.g.:

    $subject= "تجربة عنوان للرسالة";
    
Pang
  • 9,564
  • 146
  • 81
  • 122
Shehabic
  • 6,787
  • 9
  • 52
  • 93
  • Thanks, I tried all even hard coded... actually it seems error of PHPMailer, I tested it's printing Arabic on Page very good, but not in email :( – Shahzab Asif Mar 23 '13 at 22:33
1
$subject = $_POST["subject"];
$subject = "=?UTF-8?B?" . base64_encode($subject) . "?="; 
Amir
  • 4,089
  • 4
  • 16
  • 28
0

Try the old way:

$to      = 'any@mail.com';
$subject = 'Hi!';
$message = 'Whats up?';
$headers = 'From: mail@of.you.com' . "\r\n" .
        'Reply-To: noreply@blabla.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion()."\r\n";                         
$headers .= 'MIME-Version: 1.0' . "\r\n";
//if you send an html page:
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

mail($to, $subject, $message, $headers);
MeNa
  • 1,467
  • 9
  • 23
0

use this

ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

and add $mailer->CharSet = 'UTF-8';