zoffmann Posted March 13, 2007 Share Posted March 13, 2007 Hi, I would like to make a form which collects information from the visitors of the site, then this information is send to my email. everything works, but the messages are sent as UTF-8 and I would like to send as iso-8859-1 I have the following piece of code in my sendmail.php file: $mailsent = mail ($to, $subject, $message); My question is: how to format variable $message as iso-8859-1 ? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/42527-send-mail-with-iso-8859-1/ Share on other sites More sharing options...
Wuhtzu Posted March 13, 2007 Share Posted March 13, 2007 What you need is to send some "custom" headers with your message - do something like this: $to = "[email protected]"; $subject = "the subject"; $message = "the message"; $headers = 'MIME-Version: 1.0' . '\r\n'; $headers .= 'Content-type: text/html; charset=iso-8859-1' . '\r\n'; $headers .= 'From: TheSender <[email protected]>' . '\r\n'; $sendmail = mail($to,$subject,$message,$headers); The header information 'From: ' is of course optional but it is nice to show who send the mail. The 'Content-type: ' is the piece of header information which tells what the content is, plain text / html and which charset/charencoding is used... Link to comment https://forums.phpfreaks.com/topic/42527-send-mail-with-iso-8859-1/#findComment-206340 Share on other sites More sharing options...
zoffmann Posted March 13, 2007 Author Share Posted March 13, 2007 I have tried on your way but I can't receive mail at all. I have also tried like this: mail( $to, $subject, "\r\n--deadbeef-for-dinner\r\n" . "Content-Type: text/plain; " . "charset=\"iso-8859-1\"\r\n" . "Content-Transfer-Encoding: 7bit\r\n\r\n" . $message); an I get the messages but they are not formated as iso-8859-1 ??? And I didn't tell you I would like to send messages as plain text in iso-8859-1 Link to comment https://forums.phpfreaks.com/topic/42527-send-mail-with-iso-8859-1/#findComment-206349 Share on other sites More sharing options...
Wuhtzu Posted March 13, 2007 Share Posted March 13, 2007 Then just use text/plain instead $headers .= 'Content-type: text/plain; charset=iso-8859-1' . '\r\n'; But of course the text doesn't get formatted as iso-8859-1 just because you make a header which says it is so... Lets say you write this script: $to = "[email protected]"; $subject = "Sending e-mails using php"; $message = "I'm trying to send a iso-8859-1 formatted/encoded e-mail but it just wont work"; $headers = 'MIME-Version: 1.0' . '\r\n'; $headers .= 'Content-type: text/html; charset=iso-8859-1' . '\r\n'; $headers .= 'From: PHP Script <[email protected]>' . '\r\n'; $sendmail = mail($to,$subject,$message,$headers); and then save it using UTF-8 the e-mail will of content will of course be formatted/encoded using UTF-8 and not iso-8859-1 as your header says. So you have to make sure that the text you are actually sending is formatted/encoded with iso-8859-1... Link to comment https://forums.phpfreaks.com/topic/42527-send-mail-with-iso-8859-1/#findComment-206352 Share on other sites More sharing options...
zoffmann Posted March 13, 2007 Author Share Posted March 13, 2007 Thanks, I'll try your suggestion tomorrow. I hope it works, thanks one more time. Link to comment https://forums.phpfreaks.com/topic/42527-send-mail-with-iso-8859-1/#findComment-206358 Share on other sites More sharing options...
zoffmann Posted March 14, 2007 Author Share Posted March 14, 2007 I have two files: the form.html (collecting information) is saved as UTF-8 and sendmail.php (sending information as email) is saved as UTF-8 If i don't use your piece of code If I look in my "yahoo" mail account and change to UTF-8 in my browser then everything is all right. If I look in my "webmaster mail" account: browser changes automatically to UTF-8 and letters are wrong anyway. Now after some changes I have to send emails from the form to the "webmaster" account and I don't care which encoding to use only if it works in webmaster account: What shall I do ? ??? Link to comment https://forums.phpfreaks.com/topic/42527-send-mail-with-iso-8859-1/#findComment-206855 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.