0
votes

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.

2
Don't build your own mime emails. Use phpmailer or swiftmailer, both of which make this sort of thing utterly trivial.Marc B
@Fred-ii- i already did all of the guide in the link. still same issue.user2488619
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 stackoverflow.com/q/22688524Funk Forty Niner
nevermind, i found the solution and answered the question. ty for the time you spent.user2488619

2 Answers

0
votes

i just needed to add this :

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

all went fine.

0
votes

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)

;