0

i'm using a simple php mail code, to make a contact form. here is the code :

<?php $name = $_POST['name'];
   $email = $_POST['email'];
   $message = $_POST['message'];
   $formcontent="From: $name \n Message: $message";
   $recipient = "info@cactuspics.com";
   $subject = $_POST['subject'];
   $mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("ERROR");
   echo "EMAIL SENT";
?>

but the problem is that when i get the email in my mailbox, its encoded in ANSI. something like this :

با سلام به گالري

is there a way to force php to send these information in UTF-8 formatting? because my visitors use arabic characters in contact form.

i tried to use this, but still didn't work :

'=?utf-8?B?'.base64_encode($formcontent).'?='

also i have to note, that i declared charset=utf8 in the meta tag of my HTML page.

any help is appreciated.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • See http://stackoverflow.com/questions/279170/utf-8-all-the-way-through – Funk Forty Niner Aug 26 '14 at 21:53
  • Don't build your own mime emails. Use phpmailer or swiftmailer, both of which make this sort of thing utterly trivial. – Marc B Aug 26 '14 at 21:58
  • @Fred-ii- i already did all of the guide in the link. still same issue. –  Aug 26 '14 at 22:03
  • I tested your code as is, with no encoding and it went out fine. Does the message body contain extended characters? Spanish, Arabic etc. Plus, is this related to Outlook? As per http://stackoverflow.com/q/22688524/ – Funk Forty Niner Aug 26 '14 at 22:11
  • nevermind, i found the solution and answered the question. ty for the time you spent. –  Aug 26 '14 at 22:25

2 Answers2

0

i just needed to add this :

$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";

all went fine.

0

This is just an example, change values......

$header = "From: contact@".$_SERVER["SERVER_NAME"]."\n";
$header .= "Content-Type: text/html; charset=utf-8\n";
$recipient = "info@cactuspics.com"
$subject = $_POST['subject'];

    $body='<table width="90%" border="0">
    <tr>
    <td><b>Name:</b></td> <td>'.$name.'</td>
    </tr>
    <tr>
    <td><b>Email:</b></td> <td>'.$email.'</td>
    </tr>
    <tr>
    <td><b>Message:</b></td> <td>'.$message.'</td>
    </tr>
    <tr></table>';

    $res=@mail($recipient,$subject,$body,$header)

;

Edwin Thomas
  • 1,186
  • 2
  • 18
  • 31