?
Solved

php mail - endline not working correctly

Posted on 2009-07-08
6
Medium Priority
?
283 Views
Last Modified: 2013-12-13
within the email being retrieved in the email, i am getting results like \r\n within the content.  I have read online where people are suggesting using double quotes.  The problem is the value is of the message is being retrieved from post.  How can i solve this problem?
//this is not the exact code... i dont have access to the code at the moment
$to = 'example@yahoo.com';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
$msg = isset($_POST['msg']) ? mysql_escape_string($_POST['msg']) : " ";
 
<form method='post' name='iform'>
  <p>
     <label for='msg'>
     <textarea name='msg'></textarea>
  </p>
 
 mail($to, $subject,  $msg, $headers);
</form>

Open in new window

0
Comment
Question by:ndenson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 1000 total points
ID: 24805179
Don't use mysql_escape_string(). This function is for escaping strings for use in SQL statements.
0
 
LVL 18

Assisted Solution

by:Mark Gilbert
Mark Gilbert earned 1000 total points
ID: 24817832
Can I suggest that you look at the phpmailer classes instead of using the mail function.

http://sourceforge.net/projects/phpmailer/

The mail function is very powerful in what it can handle but can be a real pain to get all the elements of what you are trying to achieve to meld together error free. the phpmailer classes help you greatly with configurations for all kinds of mail servers, as well as easy to use examples to do plain text emails, html, html with inline attachments, etc. The examples are very easy to follow too.

Hope this helps.
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 25008349
The asker got \r\n characters in his email, mysql_escape_string() creates such characters. It is very likely the reason for this error, and the correct advise is to not use this function for email messages. In my opinion my answer http:#a24805179 was correct.
0
 
LVL 18

Expert Comment

by:Mark Gilbert
ID: 25019819
Angel, recommended disposition is a split between cxr and ingwa. The mysql_escape_string causes issues as stated by cxr and the phpmailer classes work to ensure emails are correctly formatted when used correctly.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question