Here is my contact function :
public static function contact_anon()
{
$form = new Form('contact_anon');
$form->field('email', 'text', array
(
'max_length' => 45,
'valid_email' => true
));
$form->field('message', 'textarea', array
(
'max_length' => 400,
'min_length' => 25
));
if($data = $form->validate())
{
$envoi = array
(
'message' => $data['message'],
'email' => $data['email']
);
mail('mymail@gmail.com', lang('contact_anon'), lang('contact_anon_text', $envoi), 'From: noreply@'.$_SERVER['HTTP_HOST']);
}
return $form;
}
Then I have this other php file with the content text that will be sent + the message from the form :
<?php
fw::$lang = array_merge(fw::$lang, array
(
'contact_anon_text' => "You have been contacted :
Message : {message}
Mail : {email}"
));
The form is working well, but the {message} doesn’t display correctly, for example :
j\'écris avec des accents pour voir si ça marche.
The website has a UTF8 charset, but I don’t know about php, I tried the following :
'message' => htmlentities((utf8_decode($data['message']), ENT_QUOTES),
But it returns :
syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting '('
I know there is hundreds of posts about UTF8, I checked them, read the php mnual and sql manual, but couldn’t understand so much as I am a beginner and not english speaker.
I also have the same problem when sending a text field to the database, eventhough the database is using utf8_general_ci. So I guess it’s definitely a problem with my php code. I am using a MVC scripts with controllers. To solve partially the SQL problem, I use :
return mysql_real_escape_string($string);
....
db::escape($username)
So the output is correct, but I had prefer to configure php to use UT8 and allows special characters like french accents.
Try saving your file with encoding UTF-8.
If you are using visual studio go to File, Save As, Save With Encoding and choose Unicode(UTF-8 without signature).