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 protected]; $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); ?> Link to comment https://forums.phpfreaks.com/topic/146808-mail-function-multiple-lines/ Share on other sites More sharing options...
trq Posted February 25, 2009 Share Posted February 25, 2009 <?php $to = '[email protected]'; $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); ?> Link to comment https://forums.phpfreaks.com/topic/146808-mail-function-multiple-lines/#findComment-770767 Share on other sites More sharing options...
ejaboneta Posted February 25, 2009 Author Share Posted February 25, 2009 <?php $to = '[email protected]'; $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: [email protected]\nProduct: product1\nComments: here is the comments what I want is "Contact Name: example company Email: [email protected] Product: product1 Comments: here is the comments Link to comment https://forums.phpfreaks.com/topic/146808-mail-function-multiple-lines/#findComment-770773 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. Link to comment https://forums.phpfreaks.com/topic/146808-mail-function-multiple-lines/#findComment-770797 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? Link to comment https://forums.phpfreaks.com/topic/146808-mail-function-multiple-lines/#findComment-770801 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. Link to comment https://forums.phpfreaks.com/topic/146808-mail-function-multiple-lines/#findComment-770802 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.