pwired Posted September 29, 2014 Posted September 29, 2014 Hi I have this part in a php form: "Danke für Ihre Bestellung bei\n" . //$msg2 with contents for the client $msg2 = "=======================================\n" . "Danke für Ihre Bestellung bei\n" . "---------------------------------------\n" . "Bitte überweisen Sie den\n" . "\n" . If the form is sent, both the webshop owner and the client recieve an email. So far so good. Only the ü in für and the ü in überweisen appear garbled (strange characters) in the received email. I tried setlocale(LC_ALL, "de_DE.UTF-8"); in the php form and I do not have setlocale(LC_ALL, "de_DE.UTF-8"); in config.php But that did not help.
netcarver Posted September 29, 2014 Posted September 29, 2014 How is the email being sent? PHP's mail() function, PW's wiremail or a third party solution? If it's PHP's mail() function are you sending a charset as part of your content-type header? 1
pwired Posted September 29, 2014 Author Posted September 29, 2014 I use mail($form, "Ihre Bestellung", $msg2, "'Content-type: text/plain; charset=UTF-8'"); I already have some result with this part what I added "'Content-type: text/plain; charset=UTF-8'"); but now I receive 2 times an email on the clients email address Guess I am not using the right format in mail
pwired Posted September 29, 2014 Author Posted September 29, 2014 How do I add Content-type: text/plain; charset=UTF-8 correctly inside the following; mail($form, "Ihre Bestellung", $msg2, "From: $form"); to make the ü appear corrctly in the received emails ?
pwired Posted September 29, 2014 Author Posted September 29, 2014 Ok got it working with this: mail($emailTo, "Bestellung", $msg1, $header = "MIME-Version: 1.0\r\nContent-type: text/plain; charset=UTF-8\r\n"); Now the ü appears correctly in the received emails. Can anyone confirm that this is 100 % code tight ? Edit: tried a few test orders and all looks well in the received emails with ü and ö
jan Posted September 29, 2014 Posted September 29, 2014 I thinks it's not exactly your question, but I also remember a lot of problems with php mail and encoding… If every thing works in the body part of the mail, but you have issues with umlauts in the subject try: $subject = '=?UTF-8?B?'.base64_encode($subject).'?=; Good luck 2
netcarver Posted September 29, 2014 Posted September 29, 2014 @pwired Glad you got it working. Can anyone confirm that this is 100 % code tight ? Can't answer your question as I have no idea what "100 % code tight" means.
pwired Posted September 29, 2014 Author Posted September 29, 2014 something is 100% water tight or code tight just my own creation Edit: php mail is quite fun. Always used email clients to send emails. Never thought that I would send emails making my own headers and email body html. 1
netcarver Posted September 29, 2014 Posted September 29, 2014 Ah, OK. Well, that depends on where the $msg1 and $emailTo fields come from and if you trust them to never have anything malicious in them. If they can have something malicious (like a frontend user entering an email address, or anything that gets made part of $msg1) then, no, this is definitely not "code tight". Always sanitize user input. Please look at PWs sanitizer class; it has methods specifically for making email addresses and general text more "code tight." It's also not code tight as it totally ignores the return value of the mail() call - so you'll never know if the send failed. You can also simplify your example by getting rid of the assignment to $header in the call. Here's the last two points put together. I'll leave the sanitization research to you as it's important you find out about it. $result = mail($emailTo, "Bestellung", $msg1, "MIME-Version: 1.0\r\nContent-type: text/plain; charset=UTF-8\r\n"); if (!$result) { // email send failed. } else { // send succeeded } 2
pwired Posted September 29, 2014 Author Posted September 29, 2014 Thanks for those 2 points, malicous input and return value, and your code example.
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