filoaman Posted February 10, 2012 Share Posted February 10, 2012 Hello friends. First of all note that i'm just an amateur php programmer, so please if what i ask is very dam don't shoot me... I already search the form and found some solutions to send UTF-8 e-mail message using PHP, but for some reason i have to use the above code. The problem is that this code doesn't send UTF-8 e-mail messages. If you can help me please do it. Thank you <? php $subject = "my subject in UTF-8"; $emailadd = '[email protected]'; $url = "http://www.mySite.com/"; $req = '0'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty. $text = "Results from form:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') {echo "$key is empty";die;} } $j = strlen($key); if ($j >= 40) {echo "Name of form element $key cannot be longer than 20 characters";die;} $j = 40 - $j; for ($i = 1; $i <= $j; $i++) {$space .= ' ';} $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } mail($emailadd, $subject, $text, 'From: '.$emailadd.''); echo '<META HTTP-EQUIV=Refresh charset=utf-8 CONTENT="0; URL='.$url.'">'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/256804-send-utf-8-e-mail-message-using-php/ Share on other sites More sharing options...
jorgepinho Posted February 10, 2012 Share Posted February 10, 2012 Hi, You need to set the encoding in the 4th argument, and not in the PHP output: $headers = 'Content-type: text/html; charset=utf-8' . "\r\n"; Plz check the manual, you will find lots of examples: http://php.net/manual/en/function.mail.php Quote Link to comment https://forums.phpfreaks.com/topic/256804-send-utf-8-e-mail-message-using-php/#findComment-1316512 Share on other sites More sharing options...
filoaman Posted February 10, 2012 Author Share Posted February 10, 2012 @jorgepinho Thank you for your answer. I had already visit, read and try examples from the web page you suggest. My problem is that i can't understand where to put this "magic line" $headers = 'Content-type: text/html; charset=utf-8' . "\r\n"; ...and how to use this variable ("$headers"). I try something like this: mail($emailadd, $subject, $text, 'From: '.$emailadd., $headers''); but in this case the mail function don't even send the mail! Can you help me more please with the "4th argument", what do you mean exactly? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/256804-send-utf-8-e-mail-message-using-php/#findComment-1316526 Share on other sites More sharing options...
jorgepinho Posted February 10, 2012 Share Posted February 10, 2012 Hi, You need to learn PHP syntax also, here is an example I *copied* from that page: Change it to your needs $to = '[email protected]'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: [email protected]' . PHP_EOL. $headers .= 'Reply-To: [email protected]' . PHP_EOL . $headers .= 'X-Mailer: PHP/' . phpversion(); $headers .= 'Content-type: text/html; charset=utf-8' . PHP_EOL; mail($to, $subject, $message, $headers); Quote Link to comment https://forums.phpfreaks.com/topic/256804-send-utf-8-e-mail-message-using-php/#findComment-1316534 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.