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
Solved

php mail - endline not working correctly

Posted on 2009-07-08
6
278 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:Mark Gilbert
Mark Gilbert 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: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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php help 34 58
MVC - procedural PHP 10 35
PHP breaks when used in Wordpress template file 3 30
How do I correctly structure this?   PHP / PDO / CSV download 1 19
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

840 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