No Carriage return from <textarea> tag ??

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 */
MYSQL_CLOSE();

require("class.phpmailer.php");

$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 = "";

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}
echo "<B>Billing has been sent</b>";
?>
greetrufusAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
_Marcel_Connect With a Mentor Commented:
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.
0
 
ldbkuttyConnect With a Mentor Commented:
Try using nl2br ( http://www.php.net/nl2br )
0
 
greetrufusAuthor Commented:
Ok, looked up, but how to implement???
0
 
greetrufusAuthor Commented:
$detail = nl2br($detail);

did it.

Perfect!

Thank you for all your help!!
0
All Courses

From novice to tech pro — start learning today.