ejaboneta Posted February 25, 2009 Share Posted February 25, 2009 I'm trying to email a form with multiple lines of information. I want the information included in the body of the message each on its own line. I know its probably really simple but I can't fingure it out. I read somewhere to use \n or \r for new lines but thats not working. <?php $to = 'email@address.com; $subject = 'Form Subject'; $message = 'Contact Name: ' . $_POST[name]; $message = $message . 'Company Name: ' . $_POST[company] . '\\r\\n'; $message = $message . 'Email: ' . $_POST[email] . '\\r\\n'; $message = $message . 'Product: ' . $_POST[description] . '\\r\\n'; $message = $message . 'Comments: ' . $_POST[body] . '\\r\\n'; $headers = "From: $email"; mail ($to,$subject, $message, $headers); ?> Quote Link to comment Share on other sites More sharing options...
trq Posted February 25, 2009 Share Posted February 25, 2009 <?php $to = 'email@address.com'; $subject = 'Form Subject'; $message = 'Contact Name: ' . $_POST['name']; $message .= 'Company Name: ' . $_POST['company'] . "\n"; $message .= 'Email: ' . $_POST['email'] . "\n"; $message .= 'Product: ' . $_POST['description'] . "\n"; $message .= 'Comments: ' . $_POST['body'] . "\n"; $headers = "From: $email"; mail ($to,$subject, $message, $headers); ?> Quote Link to comment Share on other sites More sharing options...
ejaboneta Posted February 25, 2009 Author Share Posted February 25, 2009 <?php $to = 'email@address.com'; $subject = 'Form Subject'; $message = 'Contact Name: ' . $_POST['name']; $message .= 'Company Name: ' . $_POST['company'] . "\n"; $message .= 'Email: ' . $_POST['email'] . "\n"; $message .= 'Product: ' . $_POST['description'] . "\n"; $message .= 'Comments: ' . $_POST['body'] . "\n"; $headers = "From: $email"; mail ($to,$subject, $message, $headers); ?> Thats what I meant.. the \ was taken out of my code. when I use that, I get an email with "Contact Name: example company\nEmail: name@email.com\nProduct: product1\nComments: here is the comments what I want is "Contact Name: example company Email: name@email.com Product: product1 Comments: here is the comments Quote Link to comment Share on other sites More sharing options...
trq Posted February 25, 2009 Share Posted February 25, 2009 Post your code. \n must be within double quotes to work. Quote Link to comment Share on other sites More sharing options...
ejaboneta Posted February 25, 2009 Author Share Posted February 25, 2009 Ah, that was it... I didn't know there was a difference between double and single quotes... Can you tell me when each should be used? Quote Link to comment Share on other sites More sharing options...
trq Posted February 25, 2009 Share Posted February 25, 2009 Double quotes interpolate variables and special chars such as \n Single quotes do not. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.