Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to format message body of email?

Tags:

php

i have developed a simple php contact form, that's working fine, but i am unable to format the body of the message as per my requirement, my code is given below, i am getting mail in a single line format,

where i want every information on a new line like this
"Name: Syed Sheeraz Ahmed
Contact No: 03453594552
Email: [email protected]
Address: R-47, Sector 9, North city.
Requirement: hello how are you"

<?php
$to = "[email protected]";
$subject = "From Website Contact Form";
$name = $_REQUEST['name'] ;
$contact = $_REQUEST['contact'] ;
$address = $_REQUEST['address'] ;
$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>"; 
$MESSAGE_BODY .= "Contact No: ".$_POST["contact"]."<br>"; 
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"; 
$MESSAGE_BODY .= "Address: ".$_POST["address"]."<br>"; 
$MESSAGE_BODY .= "Requirement: ".nl2br($_POST["message"])."<br>"; 
$message = $_REQUEST['message' + 'address' + 'contact'] ;
$from = $_REQUEST['email'] ;
$headers = "From:" . $from;
mail($to,$subject,$MESSAGE_BODY,$headers);
echo "Mail Sent.";
?> 
like image 740
Sheery Avatar asked Apr 13 '11 08:04

Sheery


People also ask

How do I format an email message?

How To Format an Email Message. Your email message should be formatted like a typical business letter, with spaces between paragraphs and no typos or grammatical errors. Don't mistake length for quality—keep your email brief and to the point. Avoid overly complicated or long sentences.

Can you Format Text in an email message?

HTML formatting allows you to change the format of the text in your email as well as include pictures. Formatting options include font, font size and color, font style (bold, italic, underline), highlight color, indent and spacing, and bullet and numbering styles.

How do you mention the body of an email?

Use @ in the body of a message or meeting invite In the body of the email message or calendar invite, enter the @ symbol and the first few letters of the contact's first or last name.


1 Answers

You want a new line (\n) not an HTML line break (<br>) since your email isn't marked as having an HTML body (and emails that have HTML bodies should really have multipart MIME bodies with both plain text and HTML versions since "HTML only" is a nice flag for spam detectors).

like image 79
Quentin Avatar answered Sep 27 '22 21:09

Quentin