Reputation: 11
I am having trouble getting the scandinavian letters ÆØÅ/æøå to work in my email form. The form sends the message and I recieve it just fine, except when there is ÆØÅ/æøå in the message.
Any help is highly appreciated!
<?php
header('Content-type: text/html; charset=utf-8');
$header = "Content-type: text/plain; charset=utf-8\r\n";
session_start();
ob_start();
$dontsendemail = 0;
$possiblespam = FALSE;
$strlenmessage = "";
$email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$emailaddress = array();
$emailaddress[1] = "[email protected]";
$emailaddress[2] = "[email protected]";
$emailaddress[3] = "[email protected]";
$emailaddress[4] = "[email protected]";
$contactnameindex = $_POST['emailaddress'];
if ($contactnameindex == 0 || !isset($_POST['emailaddress'])) echo '<div id="notification" class="info_div"><span class="ico_cancel">Du valgte ikke en mottaker.</span></div>';
else $emailaddress = $emailaddress[$contactnameindex];
function checkcaptcha() {
if ($_SESSION["pass"] != $_POST["userpass"]) {
echo '<div id="notification" class="info_div"><span class="ico_cancel">Beklager, men feilet i å skrive inn bildeverifiseringen. Merk at bildeverifiseringen krever at du skiller imellom store og små bokstaver.</span></div>';
return 1;
}
}
function checkemail($field) {
// checks proper syntax
if( !preg_match( "/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$/", $field))
{
echo '<div id="notification" class="info_div"><span class="ico_cancel">Feilaktig e-postadresse registrert.</span></div>';
return 1;
}
}
function spamcheck($field) {
if(eregi("to:",$field) || eregi("cc:",$field) || eregi("\r",$field) || eregi("\n",$field) || eregi("%0A",$field)){
$possiblespam = TRUE;
}else $possiblespam = FALSE;
if ($possiblespam) {
echo '<div id="notification" class="info_div"><span class="ico_cancel">Mulig forsøk på spam oppdaget. Hvis dette ikke er tilfelle, kan du redigere innholdet i kontaktskjemaet, og prøv igjen.</span></div>';
return 1;
}
}
function strlencheck($field,$minlength,$whichfieldresponse) {
if (strlen($field) < $minlength){
die($whichfieldresponse);
return 1;
}
}
if ($dontsendemail == 0) $dontsendemail = checkcaptcha($email);
if ($dontsendemail == 0) $dontsendemail = checkemail($email);
if ($dontsendemail == 0) $dontsendemail = spamcheck($email);
if ($dontsendemail == 0) $dontsendemail = spamcheck($subject);
if ($dontsendemail == 0) $dontsendemail = strlencheck($email,10,'<div id="notification" class="info_div"><span class="ico_cancel">E-mail feltet er for kort.</span></div>');
if ($dontsendemail == 0) $dontsendemail = strlencheck($subject,5,'<div id="notification" class="info_div"><span class="ico_cancel">Emnefeltet er for kort.</span></div>');
if ($dontsendemail == 0) $dontsendemail = strlencheck($message,10,'<div id="notification" class="info_div"><span class="ico_cancel">Meldingen er for kort.');
if ($dontsendemail == 0) $dontsendemail = strlencheck($emailaddress,8,'<div id="notification" class="info_div"><span class="ico_cancel">Du har ikke valgt en mottaker av meldingen.</span></div>');
if ($dontsendemail == 0){mail($emailaddress, "Emne: $subject","Fra: $email", $message); echo '<div id="sent" class="info_div"><span class="ico_success">Takk! Din e-post til oss er registrert og vil bli besvart innen 24-timer på dagene Mandag-Fredag.</span></div>'; }
ob_end_flush();
?>
Upvotes: 0
Views: 2433
Reputation: 360702
Nowhere in your mail's body do you specify the character set of the content. The header()
call you do at the top of the script does NOT apply to the email, it applies only to the output of the script sent to browser running this script.
Since it's an HTML email, you'd have to put a meta tag into the mail's <head>
block:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
However, please don't build a MIME/html mail like this by hand. It's far too ugly. Use either Swiftmailer or PHPMailer which do all the heavy work for you automatically. They're quick, easy, and free.
Upvotes: 1
Reputation: 449475
For historical reasons, the standard E-Mail encoding is ISO-8859-1.
To send your characters properly, you must either encode the E-mail explicitly as UTF-8 as shown here: PHP Send UTF-8 mail without PEAR::Mail PEAR::Mail_Mime
Alternatively, you could use utf8_decode()
to turn the text into ISO-8859-1. That will, however, work only for western characters (= those covered by ISO-8859-1) - using UTF-8 all the way is the much better alternative.
Upvotes: 0
Reputation: 50976
Don't you forgot your browser encoding ? and also email-client encoding?
Additionally, you can't send an array to a mail(); function EDIT: additionally, you should not use eregi(); as it's deprecated
Upvotes: 0