PDA

View Full Version : My Web Form Sends 3 E-Mails Each Time (Please Help)



Dankees
11-06-2013, 03:34 AM
I'm sure it's an easy fix (because I have the whole thing running well), but, when I use the web form on my web-site, I get 3 e-mails every time there is a web form submission.

Why is that? And, how can I make it so that I only get one?

http://www.FinancialAidFiler.com/Form/Form-Page.html


Thank you,
Dan

jscheuer1
11-06-2013, 04:10 AM
Although it's possible this is a javascript problem, it probably is not. So the first thing you should do is determine if it is. The easiest way to do that would be to remove the javascript from the page. First make a backup copy of the page, just in case. Then get rid of:


<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>

and:


<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator = new Validator("myemailform");
frmvalidator.addValidation("name","req","Please provide your name");
frmvalidator.addValidation("email","req","Please provide your e-mail address");
frmvalidator.addValidation("email","email","Please enter a valid e-mail address");
</script>

Clear the browser cache and refresh the page. Then do a test. If you're still getting 3 emails, it's not the javascript. Most likely then it's server side code on or used by form-to-email.php.


And by the way, this is going to be hard to help you with because we cannot test it directly. There's no way for us to know how many emails you're getting. And because we cannot easily see or test the server side code on or used by form-to-email.php.

Dankees
11-06-2013, 04:56 AM
Thanks.

Does anything look weird/funny in the "form-to-email.php" page?

jscheuer1
11-06-2013, 05:12 AM
Yes it's very funny. Sorry, just kidding. But that's what I was saying:


we cannot easily see or test the server side code on or used by form-to-email.php

First we cannot see it. If you could post the code, we could have a look at it. Second, even if we see it, it's not always clear what server side code is doing, it often relies upon other server side code not on that page. Servers can vary as well. What might cause an error on one might not on another.

Before we get into any of that, please do as I suggested and determine if it's the javascript or not by removing the javascript and testing it without that to see if it still gives 3 emails.

If it's not the javascript, please start a new thread in the PHP section and include the source code of the form-to-email.php file.

Dankees
11-06-2013, 01:03 PM
I tried what you said (removing the scripts), and I am still getting two e-mails. (One time I was getting three, but that may have been a fluke. I was typically getting two e-mails).

What else can I try?

Dankees
11-06-2013, 01:06 PM
Oh, and here is the code from the PHP page:


<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$visitor_email = $_POST['visitor_email'];
$phone = $_POST['phone'];
$emailcheckbox = $_POST['emailcheckbox'];
$phonecheckbox = $_POST['phonecheckbox'];
$fafsacheckbox = $_POST['fafsacheckbox'];
$cssprofilecheckbox = $_POST['cssprofilecheckbox'];
$verificationcheckbox = $_POST['verificationcheckbox'];
$tapcheckbox = $_POST['tapcheckbox'];
$loanassistancecheckbox = $_POST['loanassistancecheckbox'];
$consultationcheckbox = $_POST['consultationcheckbox'];
$nassau = $_POST['nassau'];
$suffolk = $_POST['suffolk'];
$borough = $_POST['borough'];
$learn = $_POST['learn'];
$comments = $_POST['comments'];

//Validate first
if(empty($firstname)||empty($visitor_email))
{
echo "Name and e-mail address are mandatory!";
exit;
}

if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}

$email_from = 'Contact@FinancialAidFiler.com';//<== update the email address
$email_subject = "FinancialAidFiler.com E-Mail Inquiry";
$email_body = "Name: $firstname $lastname.\n".
$email_visitor_email = "E-Mail: $visitor_email.\n".
$email_phone = "Phone Number: $phone.\n".
$email_emailcheckbox = "Contact Preference: $emailcheckbox\n".
$email_phonecheckbox = "Contact Preference: $phonecheckbox.\n".
$email_fafsacheckbox = "Interested In: $fafsacheckbox.\n".
$email_cssprofilecheckbox = "Interested In: $cssprofilecheckbox.\n".
$email_verificationcheckbox = "Interested In: $verificationcheckbox.\n".
$email_tapcheckbox = "Interested In: $tapcheckbox.\n".
$email_loanassistancecheckbox = "Interested In: $loanassistancecheckbox.\n".
$email_consultationcheckbox = "Interested In: $consultationcheckbox.\n".
$email_nassau = "Nassau County: $nassau.\n".
$email_suffolk = "Suffolk County: $suffolk.\n".
$email_borough = "Borough: $borough.\n".
$email_learn = "How Did You Learn About Us?: $learn.\n".

"Comments:\n $comments".

$to = "Contact@FinancialAidFiler.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers,$town);
//done. redirect to ThankYou page.
header('Location: ThankYou.html');


// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}

?>

jscheuer1
11-06-2013, 03:59 PM
I'm not nearly as good with PHP as I am with javascript. But I don't see anything obvious there that would make it mail two times or more. Which is it exactly, 2 or 3? Or does it change, sometimes 2, sometimes 3? Is this with test emails that you send to yourself, or ones that users send? If it's only from users, they might be submitting the page more than once by mistake. If it's from tests of you emailing yourself, the only thing that strikes me is that there might be something wrong with the server. I have no idea for certain what that could be. My first thought was, maybe there are more than one mail() programs on the server, each in a different path, but all in the overall path of the server, and that they all fire at that command. The more I think about it, the more this seems reasonable. What kind of server is this that you're using? Who set it up? Who setup its mail program?

Oh, and it just occurred to me, there wouldn't have to be more than one mail() program in the path. If there were more than one form-to-email.php in the path, the same thing could happen I suppose.

Dankees
11-06-2013, 06:26 PM
Thanks for your help.

It seems to be three e-mails.

These are all with test e-mails from me. It doesn't show somewhere in the code why it's e-mailing more than once?

jscheuer1
11-06-2013, 07:12 PM
Not that I can tell. I mean there's only one mail() command. And it doesn't appear to be in any sort of loop. Who setup the server to handle mail? Is it possible that there are other copies of mail() around? Is it possible that there are other copies of form-to-email.php around?

djr33
11-06-2013, 07:14 PM
As John said, there's nothing there specifically that makes it send three times.

Dankees
11-06-2013, 08:56 PM
It is very odd.

Now, I have a side question...

On my site: http://www.FinancialAidFiler.com - for some reason, the two links all the way to the right load on the page a little bit further to the right than the other four links. It is really odd. All of the pages consist of one graphic - and they are all 1100px wide. I cannot figure it out no matter what I do.

Can you guys please take a look?

Thanks.

jscheuer1
11-07-2013, 02:47 AM
I'm closing this thread, it's a duplication of others or versa visa.