Zola Posted June 7, 2017 Share Posted June 7, 2017 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. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 7, 2017 Share Posted June 7, 2017 Are we talking about the "larger form" or the email body? You don't make that clear. Quote Link to comment Share on other sites More sharing options...
Zola Posted June 7, 2017 Author Share Posted June 7, 2017 I mean when the email is received from the website, it is very plain and out of alignment. I am not sure how to make it look better and at least be aligned. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 7, 2017 Share Posted June 7, 2017 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. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted June 7, 2017 Share Posted June 7, 2017 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. Quote Link to comment Share on other sites More sharing options...
Sepodati Posted June 8, 2017 Share Posted June 8, 2017 I agree with the template suggestion, but if you're opposed to that for some unknown reason, at least use a heredoc syntax to define your email string. http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.