Formatting issue

Hey folks,

I have built a larger contact form… however, when the email is delivered it looks pretty bland and ugly, and also has weird indents.

Here is my code:

// check if fields passed are empty
if(empty($_POST['name'])   ||
   empty($_POST['email'])  ||
   empty($_POST['companyname']) ||
   empty($_POST['message']) ||
echo "No arguments Provided!";
return false;
$name = $_POST['name'];
$email_address = $_POST['email'];
$companyname = $_POST['companyname'];
$position = $_POST['position'];
$phone = $_POST['phone'];
$description = $_POST['description'];
$registration = $_POST['registration'];
$address = $_POST['address'];
$message = $_POST['message'];
// create email body and send it 
$to = ''; 
$email_subject = "Contact form submitted by:  $name";
$email_body = "You have received a quote request. \n\n".
 "Here are the details:\n 
 \nName: $name \n". 
 "Email: $email_address\n  
 Company: $companyname\n  
 Position: $position\n 
 Contact Number: $phone\n  
 Business Description: $description\n 
 Registration Number: $phone\n  
 Message: \n $message";
$headers = "From: xx \n";
$headers .= "Reply-To: $email_address"; 
return true; 

Can anyone advise how I can get it all lined up first of all please?

I would also like to add some basic styling to make it a little more impressive.

Any help much appreciated.

If you want to format the email, you’ll need to look at sending it in HTML format. There are a number of articles around on how best to do that, but remember that HTML emails are pretty basic, and generally need in-line styling rather than CSS.


Do you see in my code what is causing the alignment to be off? The first two items appear on the left, the rest is indented, albeit inline but indented.

If I was to make the text a little bigger when received, how would I do that? Span styling?

Well, you have a space in the beginning of each line starting with the Company line, if the code above is formatted correctly. You could move the \n to immediately before each field name, like you have on the Name field, or just remove the space at the start of the line.

Yes, to do any text formatting you’ll need to send it as a html email, and style it accordingly. I’m not sure whether span is the way, it’s a long time since I’ve done one and even back then, I found someone offering free working templates and picked one of those and edited it. Once you’ve gone to html, the odd bits of white space above probably won’t make any difference.

Just looking in another area and I spotted this article, which might be of help.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.