I’m using a PHP email script for a contact form. There are six fields for the form:
- Name
- Phone number
- Booking Date
- Booking Time
- Comments
There’s also a hidden honeypot field for robotest. The PHP script is as follows:
<?php
$robotest = $_POST['robotest']; //just testin' for robots
$recipient = "info@mydomain.com"; //recipient
$email = ($_POST['email']); //senders e-mail adress
if((filter_var($email, FILTER_VALIDATE_EMAIL)) && ($robotest == "")) {
$Name = ($_POST['name']); //senders name
$mail_body = !!!----> WHAT DO I PUT HERE <----!!!!
$subject = "Porter Inquiry"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields
mail($recipient, $subject, $mail_body, $header); //mail command :)
} else {
print "You've entered an invalid email address!";
}
?>
You’ll notice above, where I put !!!----> WHAT DO I PUT HERE <----!!!, I’m unsure how to get multiple fields into the mail body. I’d like to include something like:
"Hello,
You have received a new booking with the following details:
Booking Time: ($_POST['time']) Booking Date: ($_POST['date'])
Additional customer comments: ($_POST['comments']);
Please respond to the customer within 30 minutes on the following
phone number: ($_POST['phone'])
Warm regards,
Robot."
I can’t find any info on how to successfully achieve this, would greatly appreciate some guidance.
I have modified Zoltan’s code a little bit. Should work now.
Hope this helps… and yes this will send mail even when the fields are empty(except the recipient field)
Dins