elis Posted July 17, 2009 Share Posted July 17, 2009 Here is a snippet of my code: <?php $contactname = db_escape_string(htmlspecialchars($_POST['name'])); $sentname = $user->name; $subject = db_escape_string(htmlspecialchars($_POST['subject'])); $body = db_escape_string($_POST['body']); //pulled in an earlier (not shown) query $contactemail = $rowA['contactemail']; $headers = 'From: ' . $user->mail . ' ' . "\r\n" . 'Reply-To: ' . $user->mail . ' ' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $headers .= 'MIME-Version: 1.0' . "\r\n"; //prevent mail from going to spam folder $header .= 'Return-Path: ' . $user->name .' < ' . $user->main . '>\r\n'; $headers .= 'Content-Type: text/plain; charset="iso-8859-1"' . "\r\n"; $mailbody = $body; $mailbody .= '\r\n- ------ \r\n Lorem ipsum'; mail($contactemail, $subject, $mailbody, $headers); ?> I'm actually not that familiar with this, so excuse any stupid oversights on my part. The sending of mail works, however, I keep receiving this: Hello\r\nThere are no new messages\r\n\r\n\r\n----\r\nLorem ipsum Instead of Hello There are no new messages ---- Lorem ipsum When entering a new line (through hitting the enter key, not actually using "\n") in my form. I wondering what I'm doing wrong. Are my headers incorrect for what I want (simple text emails)? Is it just my email that's reading it wrong (gmail)? I tried setting my emails to HTML and using nl2br(); but the same problem occurred, but with "\r\n<br />" in the emails. Quote Link to comment https://forums.phpfreaks.com/topic/166340-new-lines-are-not-appearing-properly-when-using-mail/ Share on other sites More sharing options...
ldougherty Posted July 17, 2009 Share Posted July 17, 2009 I suggest looking at PHP Mail examples and then copying one to meet your needs. http://www.w3schools.com/PHP/func_mail_mail.asp Quote Link to comment https://forums.phpfreaks.com/topic/166340-new-lines-are-not-appearing-properly-when-using-mail/#findComment-877308 Share on other sites More sharing options...
phporcaffeine Posted July 17, 2009 Share Posted July 17, 2009 These lines are likely your issue: $header .= 'Return-Path: ' . $user->name .' < ' . $user->main . '>\r\n'; $mailbody .= '\r\n- ------ \r\n Lorem ipsum'; It should be: $header .= "Return-Path: " . $user->name ." < " . $user->main . ">\r\n"; $mailbody .= "\r\n- ------ \r\n Lorem ipsum"; Notice the use of " and not ' (you'll notice that everywhere else in your script, double quotes are used to encapsulate /r/n except on those lines) The short answer: PHP looks at strings in single quotes differently than in double quotes, in single quotes PHP will always echo verbatim. In double quotes PHP will evaluate the text rather than echo verbatim. Quote Link to comment https://forums.phpfreaks.com/topic/166340-new-lines-are-not-appearing-properly-when-using-mail/#findComment-877344 Share on other sites More sharing options...
elis Posted July 18, 2009 Author Share Posted July 18, 2009 Thank you, phpORcaffine. I'll try changing them to double quotes. Quote Link to comment https://forums.phpfreaks.com/topic/166340-new-lines-are-not-appearing-properly-when-using-mail/#findComment-877674 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.