How to stop duplicate emails?
I've been using the following bit of code to send out two emails when a user completes a 'contact us' form. The first email is sent to the website owner, and the second to the person who completes the form. The code has been edited to remove any real email addresses.
<?php
$to = "joe@blogs.co.uk";
$subject = "Website enquiry". $_POST['Name'];
$body = "Name: ".$_POST['Name']."\n"."\n"."Location: ".$_POST['Location']."\n"."\n"."Email Address: ".$_POST['emailAddress']."\n"."\n"."Telephone Number: ".$_POST['TelNo']."\n"."\n"."Comments: ".$_POST['Comments']."\n"."\n";
$headers = "From: ". $_POST['emailAddress'] ."\n";
mail($to,$subject,$body,$headers);
//?>
//<?php
$to = $_POST['emailAddress'];
$subject = "Thank you for contacting Joe";
$body = "Name: ".$_POST['Name']."\n"."\n"."Location: ".$_POST['Location']."\n"."\n"."Email Address: ".$_POST['emailAddress']."\n"."\n"."Telephone Number: ".$_POST['TelNo']."\n"."\n"."Comments: ".$_POST['Comments']."\n"."\n";
$headers = "From: "."joe@blogs.co.uk"."\n";
mail($to,$subject,$body,$headers);
?>
However, it appears that the first email is sent twice. Also, the first time the email is sent it contains all the information passed from the form, and the second time it contains blanks.
I don't think that the second email is sent twice.
It was suggested that I get rid of the closing php tag at the end of the first chunk of code and the opening one at the start of the second chunk. Hence it is commented out, but this has made no difference.
Any ideas gratelly received.
