I am a noob when it comes to PHP, and barely above that when it comes to html and css. I have a simple form for potential customers to fill out, hit send, and it should send me an email. There are a multitude of how-to's on this subject and I used several to come up with my code. Initially I had limited success in the sense that I could get the email to send, but it wasn't grabbing any of the variables (name, email addy, phone, etc). I was receiving blank emails in my inbox from an unknown sender. I fixed the syntax so that it began grabbing the form data, but now the email never arrives. I know that it is getting the variables because after you hit send, the data appears on a "results page" (i have since removed that feature, but made no other changes).
I have checked my SPAM folder. It's sending to a gmail address, and I understand gmail is forgiving when it comes to delivering suspect email. I have submitted my php code to http://phpcodechecker.com/ and it comes back clean. The server that hosts my site is running php 5.2, and an SMTP service.
Would anyone be willing to review my code and point out where I went wrong?
<?php
/* Variables */
$emailSubject = 'Quote request';
$webMaster = 'myaccount@gmail.com';
/* Data */
$email = $_POST['email'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$box = $_POST['box'];
$body = <<<EOD
<br><hr><br>
Email: $email <br>
Name: $name <br>
Phone: $phone <br>
Request: $box <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
/*Results*/
$Results = <<<EOD
<html>
<head>
<title>Email Sent!</title>
<style type ="text/css">
body {
background-color: #0252aa;
font-family: Verdona, Arial, Helvetica, sans-serif;
font-size: 14px;
color: white;
}
div {
padding-left: 50px; padding-top: 40px;
}
</style>
</head>
<div>
<div align="left">Thank you for your email.</div>
</div>
</body>
</html>
EOD;
echo "$Results";
?>
This is the relevant html:
<form class="form" method="post" action="email2.php">
<p class="name">
<input type="text" name="name" id="name" placeholder="Luke Santos">
<label for="name">Name</label>
</p>
<p class="email">
<input type="email" name="email" id="email" placeholder="LukeSantos@example.com">
<label for="email">Email</label>
</p>
<p class="phone">
<input type="text" name="phone" id="phone" placeholder="(262) 555-1212">
<label for="phone">Phone</label>
</p>
<p class="box">
<textarea name="box" placeholder="What can we help you with?"></textarea>
</p>
<p class="submit">
<input type="submit" value="Send">
<input type="hidden" name="submitted" value="TRUE" />
</p>
</form>