I'm trying to send a mail containing ÅÄÖ characters (Swedish).
I've tried changing the mail header to UTF-8 and iso-8859-1, none of which works. I've also tried wrapping the text in utf8_encode() as well as mb_encode_mimeheader(), with no success. In some cases i get chinese characters instead, not really what i want.
I just tried using htmlentities() with no result.
$values = array(
'name' => $this->input->post('name'),
'email' => $this->input->post('email'),
'ref' => $this->input->post('ref'),
'sex' => $this->input->post('sex'),
'age' => $this->input->post('age'),
'question' => $this->input->post('msg'),
'ip' => $_SERVER['REMOTE_ADDR']
);
$to = '@live.se';
$subject = $values['name'] . ' har skickat en fråga!';
$message = 'Namn:'.$values['name']." \r\n";
$message .= "\r\nEmail:".$values['email']." \r\n";
$message .= "\r\nKön:".(($values['sex'] == 'f') ? 'Kvinna' : 'Man')." \r\n";
$message .= "\r\nÅlder:".$values['age']." \r\n";
$message .= "\r\nReferensnummer:".$values['ref']." \r\n";
$message .= "\r\nMeddelande: \r\n".$values['question'];
$headers = 'From: [email protected]' . "\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
'Reply-To: ' .$this->input->post('email') . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = htmlentities($message);
if(@mail($to, $subject, $message, $headers)) {
if($this->input->is_ajax_request()) {
echo 1;
}else {
$data['message']['header'] = 'Tack så mycket!';
$data['message']['content'] = 'Din fråga skickades utan problem! Jag återkommer snarast möjligt.';
echo $this->load->view('includes/header', array(), true);
echo $this->load->view('message', $data['message'], true);
echo $this->load->view('includes/footer', array(), true);
}
}else {
$fail = true;
}
I don't know if this is the best way to achieve this. But I used to use mail like this:
mail($to, "=?utf-8?B?".base64_encode($subject)."?=", $message, $headers);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With