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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.