Welcome to PHPBuilder!
JamesW;11030017 wrote:I've tried an if statement around the mail function, however this seems to just stop the email being sent.
And what did this "if statement" have as its test? That'd be kinda important. 🙂
In the below, I don't see anything that should cause mail() to be executed twice. As a matter of fact, I'm not sure what will happen at all, because PHP should be complaining (or at least ignoring) the "$post" test ... it's $POST, not $_post ... uppercase 😉
As for the isset call itself, it seems to me you'd want to check not only if the variable is set, but also if it is set to the proper value:
<?php
if(isset($_POST['submit']) && $_POST['submit']=="Whatever the form button says on it"){
$name = $_POST['booking.php'];
$contactname = $_POST['contactname'];
$business = $_POST['company'];
$date = $_POST ['date'];
$time = $_POST ['time'];
$details = $_POST['details'];
$email = $_POST['email'];
$phone = $_POST ['phone'];
$to = "example@example.com";
$subject = "You have recieved an enquiry from $business for $date. ";
$message = "You have recieved an enquiry from $business for a job on $date. \n
Details: \n
Contact name: $contactname \n
Company: $business \n
Consignment Date: $date \n
Pickup Time: $time \n
Details: $details \n
Email: $email \n
Phone Number: $phone \n";
$mail_sent = mail($to,$subject,$message);
}
if ($mail_sent) {
echo "I executed the mail function.";
} else {
echo "The mail could not be sent!";
}
?>