This question already has an answer here:
- PHP email form shooting blank emails 4 answers
The problem is that when a user sends a filled out form I am receiving empty emails, not even the form outline - completely empty besides the subject line. All the id's from the form match the $_POST data in PHP so I am not sure why it is sending empty emails. Does the mail function not work very well?
My HTML:
<form method="post" action="message-sent.php" id="contactForm">
<p>Send us a message!</p>
<input type="hidden" name="subject" value="Message from
gamestogo.ca">
<div>
<div>
<input
name="fullname" type="text" placeholder="Full Name"
id="fullName">
</div>
<div>
<input
name="phone" type="tel" placeholder="Phone Number"
id="phoneNum">
</div>
<div>
<input
name="email" type="email" placeholder="Email" id="email"
required>
</div>
<div>
<input
name="neighbourhood" type="text" placeholder="Neighbourhood"
id="neighbourhood" required>
</div>
<div>
<input
name="people" type="text"
placeholder="Approximate Number of People"
id="numPeople" required>
</div>
<div>
<input
name="preferreddate" type="text"
placeholder="Preferred Date & Time"
id="date">
</div>
<div>
<select
name="serviceStyle" placeholder="Preferred Service Style"
id="serviceStyle">
<option value="">Your preferred service style</option>
<option value="Not Sure" style="padding-top: 1.5rem;
padding-bottom: 1.5rem;">Not Sure</option>
<option value="Curbside">Curbside - Gaming party outside your
home</option>
<option value="In-House">In-House - Gaming party inside your
home</option>
</select>
</div>
<div>
<textarea
name="comment" id="comments" rows="6"
placeholder="Any Questions?"></textarea>
</div>
<button name="submit">Send Message</button>
</div>
</form>
My PHP:
<?php
$now = date("D M j G:i:s T Y");
$toAddress = "info@gamestogo.ca";
$from = $_POST['email'];
$fromAddress = "From:" . $from ."\r\n" .
"Reply-To:" . $_POST['email'] . "\r\n" .
"X-Mailer: PHP/" . phpversion();
if($from <> ""){
$body = "Please find your message from gamestogo.ca below:\n\n";
$body .= "From: " . $_POST['fullname'] . "\n";
$body .= "Phone: " . $_POST['phone'] . "\n";
$body .= "Email: " . $_POST['email'] . "\n";
$body .= "Neighbourhood: " . $_POST['neighbourhood'] . "\n";
$body .= "Preferred Service Style: " . $_POST['serviceStyle'] . "\n";
$body .= "Number of people: " . $_POST['people'] . "\n";
$body .= "Preferred Date: " . $_POST['preferreddate'] . "\n";
$body .= "Comments: " . $_POST['comment'] . "\n";
mail($toAddress, "Form Submit from gamestogo.ca.", $body, $fromAddress);
$arr = array ('success'=>true, 'message'=>"Thank you for your inquiry, we'll get back to you soon.");
header('Location: confirmation.html');
exit();
}
else{
$arr = array ('success'=>false, 'message'=>"Please fill in required fields.");
header('Location: error.html');
exit();
}