Solved

php mail - endline not working correctly

Posted on 2009-07-08
6
275 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
  • 2
  • 2
6 Comments
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 250 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:ingwa
ingwa earned 250 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:ingwa
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now