Solved

php mail - endline not working correctly

Posted on 2009-07-08
6
280 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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

732 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