Jump to content

Mail function - multiple lines


ejaboneta

Recommended Posts

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

<?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);
?>

<?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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.