1
votes

I've found and tried various solutions given in other questions about utf-encoding for special characters and other related problems, but without any success.

I have an html contact form that sends information to my mail address with a simple php script using PEAR Mail mime. I can send information containing special characters from my test site on localhost with no problems, but not after I uploaded to my server.

eg message: Test special characters: é è ç à ô

after being sent from server becomes: Test special characters: é è ç à ô

I am guessing it's an encoding problem from my web server, but am kinda stuck at how to resolve the problem.

The meta tags in file containing the form are set to:

<meta charset="utf-8"> 

and the form is specified to accept charset utf-8:

<form name="contact" method="post" action="assets/send_form.php" accept-charset="UTF-8">

I've also tried sending content from php file with:

header("Content-Type: text/html; charset= UTF-8");

as well as creating $headers for the message with 'Content-Type' = 'text/html; charset="UTF-8".

The relevant php code in my script:

//This section creates the email headers
$headerss=array(); 
$headerss['From']= $from_address; 
$headerss['To']= $siteEmail; 
$headerss['Subject']= $email_subject; 
$headerss['Return-Path']= $contactEmail; 
$headerss['Date']= date("r"); 
$headerss['Content-Type'] = 'text/html; charset="UTF-8"';  

// This section creates the smtp inputs
$auth = array('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password);

// create new Mail_mime instance, set utf-8 charset
$mail = new Mail_mime();
$mail -> setHTMLBody($email_message); 


//CHECK THIS OUT FOR UTF-8 ***************************** 

$mimeparams=array(); 
$mimeparams['text_encoding']="7bit"; 
$mimeparams['text_charset']="UTF-8"; 
$mimeparams['html_charset']="UTF-8";
$mimeparams['head_charset']="UTF-8"; 
$mimeparams['eol']= "\n" ; 

$body = $mail->get($mimeparams); 
$headers = $mail->headers($headerss); 


// This section send the email
$smtp = Mail::factory('smtp', $auth);
$sendmail = $smtp->send($siteEmail, $headers, $body);

Any help will be really appreciated. Thanks.

2
Can you verify that the encoding of $email_message is UTF-8?Halcyon
@Doge The $email_message is made from HTTP POST requests from inputs of the contact form with 'accept-charset' set to "UTF-8". The inputs are then added some formatting to create email message: eg. $email_message .= "From: ".$contactName."<br>";Hales

2 Answers

0
votes

Try to put before

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
0
votes

I experienced the same problem and my solution was to save the php file in same format, in UTF-8 as I had saved in ANSI format. That solved my problem anyway.