Bogey Posted May 5, 2013 Share Posted May 5, 2013 (edited) Hi all, I am building a website, with a contact form...When mail is send from contactform to the website owner, then not all is going wel... When I use this code: $headers = 'MIME-Version: 1.0' . "\r\n";$random_hash = md5(date('r', time()));$headers .= 'Content-type: multipart/alternative; boundary="PHP-alt-'.$random_hash.'"' . "\r\n";$headers .= 'From: ' . $afzender . '<' . $mailadres . '>'; $mail_opmaak="---DEZE EMAIL IS VERZONDEN IN HTML FORMAAT, MAAR UW EMAIL PROGRAMMA ONDERSTEUNT DIT NIET. EVENTUELE OPMAAK EN KLIKBARE LINKS ZIJN VERWIJDERD--- Hier een text versie van de email Enters werken als enters"; $mail_opmaak_html= $mail_opmaak_html . $bericht; $message='--PHP-alt-'.$random_hash.'Content-Type: text/plain; charset="utf-8"Content-Transfer-Encoding: 7bit '.$mail_opmaak.' --PHP-alt-'.$random_hash.'Content-Type: text/html; charset="utf-8"Content-Transfer-Encoding: 7bit '.$mail_opmaak_html.' --PHP-alt-'.$random_hash.'--'; $sentmail = mail($to, $onderwerp, $message, $headers); then outlook looks like this: When I use this code: $headers = 'MIME-Version: 1.0' . "\r\n";$random_hash = md5(date('r', time()));//$headers .= 'Content-type: multipart/alternative; boundary="PHP-alt-'.$random_hash.'"' . "\r\n";//$headers .= 'From: ' . $afzender . '<' . $mailadres . '>';$headers .= 'Content-type: multipart/alternative; charset="utf-8" boundary="PHP-alt-'.$random_hash.'"' . "\r\n";$headers .= 'From: ' . $afzender . '<' . $mailadres . '>'; $mail_opmaak="---DEZE EMAIL IS VERZONDEN IN HTML FORMAAT, MAAR UW EMAIL PROGRAMMA ONDERSTEUNT DIT NIET. EVENTUELE OPMAAK EN KLIKBARE LINKS ZIJN VERWIJDERD--- Hier een text versie van de email Enters werken als enters"; $mail_opmaak_html= $mail_opmaak_html . $bericht; $message='--PHP-alt-'.$random_hash.'Content-Type: text/plain; charset="utf-8"Content-Transfer-Encoding: 7bit '.$mail_opmaak.' --PHP-alt-'.$random_hash.'Content-Type: text/html; charset="utf-8"Content-Transfer-Encoding: 7bit '.$mail_opmaak_html.' --PHP-alt-'.$random_hash.'--'; $sentmail = mail($to, $onderwerp, $message, $headers); then OUTLOOK looks like this: What I want is that é is shown how it supposed to and not like é in ALL of the following items:1.) From2.) Subject3.) Message Hope you can help me Edited May 7, 2013 by Bogey Link to comment Share on other sites More sharing options...
Ingolme Posted May 5, 2013 Share Posted May 5, 2013 I'm not sure of the exact syntax for HTTP headers, but try adding a semi-colon between the parameters: $headers .= 'Content-type: multipart/alternative; charset="utf-8"; boundary="PHP-alt-'.$random_hash.'"' . "\r\n"; Link to comment Share on other sites More sharing options...
Bogey Posted May 5, 2013 Author Share Posted May 5, 2013 tried, but nothing changed... Link to comment Share on other sites More sharing options...
jeffman Posted May 6, 2013 Share Posted May 6, 2013 (edited) The appearance of headers is NOT determined by the Content-Type of the message. The header must contain its own type instructions. EDIT SEE NEXT POST What you want is some sort of iconv function. I've experimented with this, and here is the closest I can come to the exact solution $preferences = array( "input-charset" => "UTF-8", "output-charset" => "ISO-8859-1");$preferences["scheme"] = "Q";$h = iconv_mime_encode("", $subject, $preferences); This outputs something like this, which is fine : =?ISO-8859-1?Q?H=E9llo?= but the first two characters (": ") need to be stripped. If there is a truly perfect solution, someone else might know it. In theory, you should be able to do this: $h = iconv_mime_encode("Subject", $subject, $preferences); and that would give you a perfectly formed mail header. And this will work for most headers, such as BCC. But it doesn't work with the Subject header, because the mail() function creates its own Subject header. All you are permitted to send is the value of the subject header, and iconv_mime_encode() returns a name-value pair formatted as a complete header string. All this should be true for the TO header also. Edited May 6, 2013 by Deirdre's Dad Link to comment Share on other sites More sharing options...
jeffman Posted May 6, 2013 Share Posted May 6, 2013 (edited) OK, additional research turns up a much easier solution: $s = '=?UTF-8?B?' . base64_encode($subject) . '?=';mail($to, $s, "My message"); Edited May 6, 2013 by Deirdre's Dad Link to comment Share on other sites More sharing options...
Bogey Posted May 6, 2013 Author Share Posted May 6, 2013 thnx!!! going try that out asap!!!! Link to comment Share on other sites More sharing options...
Bogey Posted May 6, 2013 Author Share Posted May 6, 2013 Did between familie apointments a quick try... Still not working... But your talking about the "subject" part, but that was already quite working how supposed... (see first post)The problem is the sender/from thing, the $to.... Link to comment Share on other sites More sharing options...
jeffman Posted May 6, 2013 Share Posted May 6, 2013 Did you try the solution in Post #5? It will work on any value, including From: Link to comment Share on other sites More sharing options...
justsomeguy Posted May 6, 2013 Share Posted May 6, 2013 Outlook might also have that original value saved as the contact for that email address. Link to comment Share on other sites More sharing options...
Bogey Posted May 6, 2013 Author Share Posted May 6, 2013 (edited) When I only use this code: $to = 'info@inselsem.nl';if(!empty($_GET['c'])){$onderwerp = stripslashes($_GET['c']);} $subject = '=?UTF-8?B?' . base64_encode($onderwerp) . '?=';$sentmail = mail($to, $subject, "My message"); then I get this: Edited May 6, 2013 by Bogey Link to comment Share on other sites More sharing options...
Bogey Posted May 6, 2013 Author Share Posted May 6, 2013 Outlook might also have that original value saved as the contact for that email address. How do I clear outlook? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 6, 2013 Share Posted May 6, 2013 Find the saved contact in the address book or wherever it gets saved, and delete it. Link to comment Share on other sites More sharing options...
Bogey Posted May 6, 2013 Author Share Posted May 6, 2013 (edited) Okay, start over ;)I cleared the automaticfilled adress in Outlook... This is my code: <?phpfunction br2nl( $input ) {return preg_replace('/<br(\s+)?\/?>/i', "\n", $input);} if(!empty($_GET['a'])){$afzender = stripslashes($_GET['a']);}if(!empty($_GET['b'])){$mailadres = stripslashes($_GET['b']);}if(!empty($_GET['c'])){$onderwerp = stripslashes($_GET['c']);}if(!empty($_GET['d'])){$bericht = stripslashes($_GET['d']);} $to = 'info@inselsem.nl';$subject = '=?UTF-8?B?' . base64_encode($onderwerp) . '?='; $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https')=== FALSE ? 'http' : 'https';$host = $_SERVER['HTTP_HOST'];$website = $protocol . '://' . $host; $headers = 'MIME-Version: 1.0' . "\r\n";$random_hash = md5(date('r', time()));$headers .= 'Content-type: multipart/alternative; boundary="PHP-alt-'.$random_hash.'"' . "\r\n";$headers .= 'From: ' . $afzender . '<' . $mailadres . '>'; $mail_opmaak="---DEZE EMAIL IS VERZONDEN IN HTML FORMAAT, MAAR UW EMAIL PROGRAMMA ONDERSTEUNT DIT NIET. EVENTUELE OPMAAK EN KLIKBARE LINKS ZIJN VERWIJDERD--- Hier een text versie van de email Enters werken als enters"; $mail_opmaak_html= $mail_opmaak_html . $bericht; $message='--PHP-alt-'.$random_hash.'Content-Type: text/plain; charset="utf-8"Content-Transfer-Encoding: 7bit '.$mail_opmaak.' --PHP-alt-'.$random_hash.'Content-Type: text/html; charset="utf-8"Content-Transfer-Encoding: 7bit '.$mail_opmaak_html.' --PHP-alt-'.$random_hash.'--'; $sentmail = mail($to, $subject, $message, $headers); if($sentmail){?><p align='center'>GOOD...!</p><?php}else {?><p align='center'>FAULT...!</p><?phpreturn;}?> Subject and message show é....The From shows éRené <mail@gmail.com> So just the from needs to be fixed... I think, this problem has to be an issue for lot of people, cause many use Outlook...Or am I just stupid, that I cant get it right? Edited May 6, 2013 by Bogey Link to comment Share on other sites More sharing options...
justsomeguy Posted May 6, 2013 Share Posted May 6, 2013 You're not base64-encoding the sender, only the subject. You need to encode anything that contains UTF characters. Link to comment Share on other sites More sharing options...
Bogey Posted May 6, 2013 Author Share Posted May 6, 2013 (edited) YEAH....!!! now its working how supposed to $to = 'info@mail.nl';$subject = '=?UTF-8?B?' . base64_encode($subject) . '?=';$sender = '=?UTF-8?B?' . base64_encode($sender) . '?='; $headers = 'MIME-Version: 1.0' . "\r\n";$random_hash = md5(date('r', time()));$headers .= 'Content-type: multipart/alternative; boundary="PHP-alt-'.$random_hash.'"' . "\r\n";$headers .= 'From: ' . $sender . '<' . $mailadres . '>'; This works....!!! thnx thnx thnx thnx thnx Edited May 6, 2013 by Bogey Link to comment Share on other sites More sharing options...
jeffman Posted May 6, 2013 Share Posted May 6, 2013 (edited) FWIW, it's not just Outlook. It's every mailer I ever tried. Edited May 6, 2013 by Deirdre's Dad Link to comment Share on other sites More sharing options...
Bogey Posted May 7, 2013 Author Share Posted May 7, 2013 thanks all for the enormous help! Link to comment Share on other sites More sharing options...
Bogey Posted May 7, 2013 Author Share Posted May 7, 2013 (edited) Not totally solved :S other problem! I want for example the name "René" written to the mysql database, but I dont get the é there... I get:éé but noté this is in my code: <meta http-equiv="X-UA-Compatible" content="IE=8" /><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><meta http-equiv="Content-Language" content="nl" /> I tried different things: $sender = stripslashes($_GET['a']);} $sender= utf8_encode($sender);$sender= '=?UTF-8?B?' . base64_encode($sender) . '?='; Coallitions tried in mysql:utf8_binutf8_general_cilatin1_general_cilatin1_swedish_ci any sollutions??? And a question for dutch coders here (also for english speaking, but I prefer dutch, cause I think this is a difficult item):Is there a course/book/topic where the uncoding issue is being explained from scratch to advanced....? Edited May 7, 2013 by Bogey Link to comment Share on other sites More sharing options...
justsomeguy Posted May 7, 2013 Share Posted May 7, 2013 Your database should use the UTF8 general encoding. You need to change the content type on your page so that it is using UTF8, and you might also want to save your actual files using UTF8. After that, try to insert normally or using utf8_encode to see which works. Link to comment Share on other sites More sharing options...
Bogey Posted May 7, 2013 Author Share Posted May 7, 2013 I did what you told in the post.... I need Renénormal gives: Réneencoding gives: Réne Link to comment Share on other sites More sharing options...
justsomeguy Posted May 7, 2013 Share Posted May 7, 2013 Try utf8_decode Link to comment Share on other sites More sharing options...
Bogey Posted May 7, 2013 Author Share Posted May 7, 2013 (edited) Yes, that was it!!!!But why decode, if page is charset utf8 and database is coalition utf8? thnx again! Edited May 7, 2013 by Bogey Link to comment Share on other sites More sharing options...
justsomeguy Posted May 7, 2013 Share Posted May 7, 2013 I'm not quite sure, but I think it has to do with how the data gets sent to MySQL. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now