Jump to content

Formatting issue


Zola

Recommended Posts

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:

 
<?php
// check if fields passed are empty
if(empty($_POST['name'])   ||
   empty($_POST['email'])  ||
   empty($_POST['companyname']) ||
   empty($_POST['message']) ||
   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
   {
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 = 'xx@gmail.com'; 
$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"; 
mail($to,$email_subject,$email_body,$headers);
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.

Link to comment
Share on other sites

You need to learn how to make it an html email and use some css or at least an html table out of the body.  This might be a lot easier if you use something like PHPMailer instead of the built-in mail function.

 

Research, research, research.

Link to comment
Share on other sites

The reason why you have weird indentations is because you've put them there. Your $email_body is a completely random mixture of lines with spaces, lines without spaces, blank lines and line breaks. PHP cannot fix that for you.

 

Besides switching to PHPMailer, you should put your mail content into external template files where you can actually see the formatting. If you use a professional template engine like Twig, this is very easy and also much more secure than simply putting raw PHP variables into mail bodies.

Link to comment
Share on other sites

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.