Reputation: 49
i have been trying to grab info from a form and send it to email. it works fine unless there is arabic in the form in which case the arabic parts are shown as gibberish in the email. here is my latest trial mail code:
require_once('PHPMailer/class.phpmailer.php');
require ('diet/contact.html');
$name = htmlentities($_POST['cf-name']);
$email = htmlentities($_POST['cf-email']);
$tel = htmlentities($_POST['cf-tel']);
$complaint = htmlentities($_POST['cf-complaint']);
$hour = htmlentities($_POST['cf-hour']);
$min = htmlentities($_POST['cf-min']);
if ($_POST['cf-am'] == 'am') {
$tod = 'am';
} elseif ($_POST['cf-pm'] == 'pm') {
$tod = 'pm';
}
$day = htmlentities($_POST['cf-day']);
if (isset($_POST['cf-info']) === true && empty($_POST['cf-info']) === false ) {
$info = htmlentities($_POST['cf-info']);
}
$mail = new PHPMailer(true);
try {
$mail->AddReplyTo($email, $name);
$mail->AddAddress('[email protected]', 'Name');
$mail->SetFrom('[email protected]', 'Name 2'); //
$mail->Subject = 'موضوع';
$mail->AltBody = 'برنامه شما از این ایمیل پشتیبانی نمی کند، برای دیدن آن، لطفا از برنامه دیگری استفاده نمائید'; // متنی برای کاربرانی که نمی توانند ایمیل را به درستی مشاهده کنند
$mail->CharSet = 'UTF-8';
$mail->ContentType = 'text/html';
$mail->MsgHTML('<html>
<body><h1 style="color: #8b4513">New Contact</h1>
<h3 style="color: #006400">Hello,</h3>
You have just received a contact request with the following information:<br/><br/>
<b>Name:</b> '.$name.'<br/>
<b>Email</b>: '.$email.'<br/>
<b>Telephone number:</b> '.$tel.'<br/>
<b>Complaint:</b> '.$complaint.'<br/>
<b>His preferred time to visit:</b> '.$hour.':'.$min.' '.$tod.'<br/>
<b>His preferred day is:</b> '.$day.'<br/><br/>
<b>Additional info:</b> '.$info.'<br/><br/>
**You can reply directly to this email to email the contact.**<br/><br/>
- Have a nice day</body></html>
');
$mail->Send();
echo "پیام با موفقیت ارسال شد\n";
}
catch (phpmailerException $e) {
echo $e->errorMessage();
}
catch (Exception $e) {
echo $e->getMessage();
}
the email works fine except for any arabic input from the form. ive searched a lot for a solution but nothing seems to output the arabic font. i use mac osx mail client and icloud webmail to check both dont see the arabic parts correcly. any help is appreciated.
Upvotes: 2
Views: 1282
Reputation: 2707
Try the following, add charset right after you construct the object before specifying the Arabic text.
$mail = new PHPMailer(true);
$mail->CharSet = 'UTF-8';
Also trying encoding the body either way:
$mail->AltBody = "=?UTF-8?B?".base64_encode($arabicBody)."?=";
$mail->AltBody = "=?UTF-8?Q?".imap_8bit($arabicBody)."?=";
Upvotes: 2