Colleagues,
I have an e-mail form in PHP that does not correctly send accented words, several questions appear in words with accent, cedilla etc. I tried several things but none worked.
Can anyone give me strength? Below is the script I'm using. It is running on a Wordpress page template.
<?php
//If the form is submitted
if(isset($_POST['submitted'])) {
//Check to see if the honeypot captcha field was filled in
if(trim($_POST['checking']) !== '') {
$captchaError = true;
} else {
//Check to make sure that the name field is not empty
if(trim($_POST['contactName']) === '') {
$nameError = 'Informe seu nome.';
$hasError = true;
} else {
$name = trim($_POST['contactName']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['emaill']) === '') {
$emailError = 'Informe se endereço de e-mail.';
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['emaill']))) {
$emailError = 'Informe um endereço de e-mail válido.';
$hasError = true;
} else {
$emaill = trim($_POST['emaill']);
}
//Check to make sure comments were entered
if(trim($_POST['comments']) === '') {
$commentError = 'Escreva sua mensagem.';
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['comments']));
} else {
$comments = trim($_POST['comments']);
}
}
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = '[email protected]';
$subject = '[Contato] '.$name;
$sendCopy = trim($_POST['sendCopy']);
$body = "Name: $name \n\nEmail: $emaill \n\nComments: $comments";
$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $emaill;
mail($emailTo, $subject, $body, $headers);
if($sendCopy == true) {
$subject = 'You emailed Your Name';
$headers = 'From: Tanmay <[email protected]>';
mail($emaill, $subject, $body, $headers);
}
$emailSent = true;
}
}
} ?>
Thank you in advance.