Link to home
Start Free TrialLog in
Avatar of greetrufus
greetrufus

asked on

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>";
?>
SOLUTION
Avatar of ldbkutty
ldbkutty
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of greetrufus
greetrufus

ASKER

Ok, looked up, but how to implement???
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
$detail = nl2br($detail);

did it.

Perfect!

Thank you for all your help!!