UTF-8 format with mail()
-
Hi php folks... I decided to try to make an PHP script that a webform could call, to send an email, so I doesn't need the ugly mailto:xxx@yyy.domain in the form action. So I have 2 pages. 1 frontend (html) and 1 backend (php). The frontend contain an webform that on submit using the backend php as action, so its like: index.html sendemail.php action="sendemail.php" (in the index.html form). Everything works fine, and I recieving the emails as supposed... I have configured the php.ini to use my own smtp server (which I use at work too, so I know the SMTP server works). the issue now is, that I want to send my emails as utf-8 format, cuz the need of some special characters inside the email?!? I'm using the mail($to, $subject, $body, $header); as function right now... And when I type in some utf-8 formatted characters like ø, its viewed as ?? in the recieved email :( How can I send my email()'s as utf-8? I have try following: - Set header of the email to utf-8:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/plain; charset=utf-8' . "\r\n";
$headers .= 'From: ' . $_POST['email'] . "\r\n";I'm using Eclipse PHP as php editor for development.
$dato = date("d-m-y"); $to = "your@domain.dk"; $subject = "Web $dato"; $headers = 'MIME-Version: 1.0' . "\\r\\n"; $headers .= 'Content-Type: text/plain; charset=utf-8' . "\\r\\n"; $headers .= 'From: ' . $\_POST\['email'\] . "\\r\\n"; if($\_POST\['street'\] != "") $street = $\_POST\['street'\]; if($\_POST\['no'\] != "") $no = $\_POST\['no'\]; if($\_POST\['floor'\] != "") $floor = $\_POST\['floor'\]; if($\_POST\['name'\] != "") $name = $\_POST\['name'\]; //Set email body $newline = "\\r\\n"; $body = "Date: $dato" . $newline . $street . " " . $no . ", " . $floor . "." . $nnewline . $navn; //Send email mail($to, $subject, $body, $headers);
Whitebox test: Input: $street = "ø"; $no = "53st"; $floor = "2nd"; $name = "æøå"; $dato = "20-09-2010"; Output SHOULD be:
Date: 20-09-2010
ø 53st, 2nd.
æøåActual output:
Date: 20-09-2010
?? 53st, 2nd.
??????