I have a form that is sending 2 copies of the email when clicked, one with all the data and another with no data added. Can anyone see an error in my code or have an idea why this is happening? <?php $to ="me@me.me"; $subject ="Contact Form"; $surname = $_POST['surname']; $firstname = $_POST['firstname']; $phone = $_POST['phone']; $Mobile =$_POST['Mobile']; $address = $_POST['address']; $address2 = $_POST['address2']; $email = $_POST['email']; $message="Below is the data submitted from your form \n SurName: $surname \n FirstName: $firstname \n Phone: $phone \n Mobile: $Mobile \n Address: $address \n $address2 \n "; mail($to, $subject, $message, "From: $email\r\nReply-To: $email\r\n"); ?>
The form is in a separate html file. I removed any loops that were in the script and just kept the part that sends mail to test it and it still does it.
I did a bit of searching around on this one and it appears a common problem with very little information on a solution. However, if you have a very poorly performant system, or are using a busy shared host, it may be due to this... http://www.greatcircle.com/lists/majordomo-users/mhonarc/majordomo-users.200106/msg00130.html Something to do with messages sitting in the queue so long they get picked up by the process again or by another parallel mail process? If you have console access - try using sendmail raw from the console rather than through php. Also check the server mail logs to see if there are two copies or just one recorded in the there.
Thanks for that. The server isn't that busy, I just upgraded it. I'll look into what you suggested. Thanks again
I found a solution to this, thought I'd post it in case anyone has the same problem. I think the problem was caused by a validation javascript sending the form twice, once without parameters. (Not sure about this bit though). To solve it I put in this code foreach($HTTP_POST_VARS as $key=> $val) { $count ++; } if($count >5){ // set this to the minimum required parameters for a successful send mail($to, $subject, $message, "From: $email\r\nReply-To: $email\r\n"); }