Reputation: 1371
I have problem with non english characters with this e-mail script. If I set the script to send e-mail to my gmail account, I have no problem. However, if I set the script to send email to my domain account and if i open the email with windows live mail or with microsoft outlook then the e-mail is not readable. I must to go to encoding menu, and then select the utf-8, and then i can read the email.
If I open the mail on iMac mail client, i have no problem.
My customer see this as big problem and want me to solve it. Anyone can help?
Here is the code:
<?php
// send the form to the specify email
// CONFIG VARS
$subject = "mysite.com | contact form";
$to = "[email protected]";
$from = '[email protected]';
//data
$msg = "Name: " .$_POST['namesup'] ."<br>\n";
$msg .= "Email: " .$_POST['emailsup'] ."<br>\n";
$msg .= "Phone: " .$_POST['phonesup'] ."<br>\n";
$msg .= "Message: " .$_POST['yourtextsup'] ."<br>\n";
//Headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from. ">" ;
//send
mail($to, $subject, $msg, $headers);
?>
Any help will be deeply appreciated. Zoran
Upvotes: 1
Views: 934
Reputation: 8094
Checkout this code it will work for me,
<?php
$subject = "mysite.com | contact form";
$to = "[email protected]";
$from = '[email protected]';
$msg = '<html>
<head>
</head>
<body>
<p>
Name: ".$_POST['namesup']."<br>
Email: ".$_POST['emailsup']."<br>
Phone: ".$_POST['phonesup']."<br>
Message: ".$_POST['yourtextsup']."<br>
</p>
</body>
</html>';
$headers = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= "X-Mailer: PHP \r\n";
$headers .= "From: <".$from. ">" ;
mail($to,$subject,$msg,$headers);
?>
This line $headers = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n";
is resolved your issue of like Arabic language or others.
Upvotes: 1
Reputation: 439
Try changing your scripts charset to:
<?php
// send the form to the specify email
// CONFIG VARS
$subject = "mysite.com | contact form";
$to = "[email protected]";
$from = '[email protected]';
//data
$msg = "Name: " .$_POST['namesup'] ."<br>\n";
$msg .= "Email: " .$_POST['emailsup'] ."<br>\n";
$msg .= "Phone: " .$_POST['phonesup'] ."<br>\n";
$msg .= "Message: " .$_POST['yourtextsup'] ."<br>\n";
//Headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1";
$headers .= "From: <".$from. ">" ;
//send
mail($to, $subject, $msg, $headers);
?>
Upvotes: 0
Reputation: 4356
I would suggest making sure your message is valid HTML, including the <html>
and <head>
tags, and also make sure you include the <meta http-equiv="Content-Type" content="text/html charset=UTF-8" />
tag. So:
//data
$msg = '<html><head><meta http-equiv="Content-Type" content="text/html charset=UTF-8" /></head><body>';
$msg .= "Name: " .$_POST['namesup'] ."<br>\n";
$msg .= "Email: " .$_POST['emailsup'] ."<br>\n";
$msg .= "Phone: " .$_POST['phonesup'] ."<br>\n";
$msg .= "Message: " .$_POST['yourtextsup'] ."<br>\n";
$msg .= '</body></html>';
Upvotes: 0