No Carriage return from <textarea> tag ??

Posted on 2005-03-31
Medium Priority
Last Modified: 2013-12-13
The following code updates a mysql database and also emails content.
The problem I am having is:

<textarea rows="10" cols="55" name="detail" size="300"></textarea>

is the form tag in my html page.

When the email is send, there are no carriage returns in the message body.
All the text entered in the detail textarea is crammed together.
How do I get the code to recognize the carriage returns?

Here is my code:

$hostname = "localhost";
$username = "username";
$password = "passwd";
$dbName = "consultDB";

/* MySQL table created to store the data */
$userstable = "consult";

/* make connection to database */
MYSQL_CONNECT($hostname,$username,$password) OR DIE("Unable to connect to database");

@mysql_select_db("$dbName") or die("Unable to select database");

/* Insert information into table */
      $query = "INSERT INTO $userstable VALUES('','$cDate','$clientID','$consultID','$hours','$detail')";
      $result = MYSQL_QUERY($query);
/* Close the database connection */


$mail = new PHPMailer();
$mail->IsSMTP();            // set mailer to use SMTP
$mail->Host = "localhost";  // specify main and backup server
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "mail";  // SMTP username
$mail->Password = "relay"; // SMTP password

$mail->From = "$email";
$mail->FromName = "$consultID";
#$mail->AddAddress("david@peteshome.com", "Josh Adams");
$mail->AddAddress("email@email.com");    // name is optional
#$mail->AddReplyTo("david@peteshome.com", "Information");

$mail->WordWrap = 50;                                 // set word wrap to 50 characters
#$mail->AddAttachment("/var/tmp/file.tar.gz");         // add attachments
#$mail->AddAttachment("/tmp/image.jpg", "new.jpg");    // optional name
$mail->IsHTML(true);                                  // set email format to HTML

$mail->Subject = "Invoice for $cDate";
$mail->Body    = "$clientID<br>$cDate $hours Hours $consultID<BR>$detail";
$mail->AltBody = "";

   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
echo "<B>Billing has been sent</b>";
Question by:greetrufus
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
LVL 32

Assisted Solution

ldbkutty earned 400 total points
ID: 13677337
Try using nl2br ( http://www.php.net/nl2br )

Author Comment

ID: 13677519
Ok, looked up, but how to implement???

Accepted Solution

_Marcel_ earned 1600 total points
ID: 13678977
Hmmm... Are you sure there are any real linebreaks in your input? Does the user indeed sents an enter? The text-area is 55 colums wide, so the text shows as lines that are max. 55 characters wide. here is no linebreak there however! By the way your PHPMailer setting has a worwrap of 50... To get the linebreaks to html you need to add the line

$detail = nl2br($detail);

just before the line

$mail->Body    = "$clientID<br>$cDate $hours Hours $consultID<BR>$detail";

This will convert all enters given in the textbox to <br> tags, just like suggested by ldbkutty.

Author Comment

ID: 13680927
$detail = nl2br($detail);

did it.


Thank you for all your help!!

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

765 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