Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP/jQuery form scripts sending duplicate emails?
    primarykey
    data
    text
    <p>I've tried to fix this problem, or find a similar problem, but I'm still scratching my head over this one.</p> <p>I have an HTML form that I'm validating with a jQuery function, then passing it to a PHP script for mailing. The problem I'm having is once the functions run, there's a duplicate mail being sent, but the second one is blank, none of the data values are passed.</p> <p><strong>The jQuery:</strong></p> <pre><code>$("#submit").click(function(){ var quit = false; if(validateName()){ name = validateName(); $("label#name_error").fadeOut(0); $("label#name_error2").fadeOut(0); } else if (validateInput('name')){ $("label#name_error").fadeOut(0); $("label#name_error2").fadeIn(250); quit = true; } else { $("label#name_error").fadeIn(250); $("label#name_error2").fadeOut(0); quit = true; } // several more validation checks for the other fields follow. if(quit){ return false; } var dataString = "name=" + name + "&amp;email=" + email; //and other fields inserted here $.ajax({ type: "POST", url: "bin/MailHandler.php", data: dataString, success: function(){ $('.error').fadeOut(0); $('#contact-form').clearForm(); $('#contact').html("&lt;div class='download-box'&gt;&lt;h2&gt;Thanks for contacting us!&lt;/h2&gt;&lt;p&gt;Someone will be in touch shortly!&lt;/p&gt;&lt;/div&gt;").fadeOut(0).fadeIn(1500); } }); return false; }); </code></pre> <p>Which then sends to the <strong>PHP</strong> (MailHandler.php):</p> <pre><code>&lt;?php $to = "email@email.com"; $from = $_REQUEST["email"]; $subject = "Testing the form " . $_REQUEST["name"]; $headers = "From: " . $_REQUEST["email"] . "\r\n" . "Reply-To: " . $_REQUEST["email"]; $messageBody = ""; $messageBody .= $_REQUEST["name"] . "\n"; $messageBody .= $_REQUEST["email"] . "\n"; //and the other fields added similarly. if (mail($to, $subject, $messageBody, $headers)){ echo ("Mail Sent"); } else { echo ("Mail Failed"); } ?&gt; </code></pre> <p>Once this runs, everything seems to process correctly, I get the success message and the email with all the correct data arrives. </p> <p>A few minutes later a second email arrives, but with none of the data from the form. All the headers and data values are blank.</p> <p>I've looked over the code, and I can't figure out where the second message is coming from. Does anyone see something I missed?? Any help is appreciated.</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload