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

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.