This Form Was Working OK

This form was working just fine, and then for some strange reason it stopped sending emails to me. I must have done something to it, but I have no idea what I did to stop it from working. The email address is valid, it just won’t send the form data to me. Here is the code.

[php]<?php

/* Check to see if the html was sent via $_POST /
if ($_SERVER[“REQUEST_METHOD”] == “POST”){
/
If true we continue on with the script /
/
Subject and Email Variables */

$emailSubject = '2017 Windemuth Family Reunion Registration Form';

/* Gathering Data Variables */
/*compare the email address */
if($_POST['email'] != $_POST['confirm']) {
    #set error...
    $error .= 'The email addresses do not match, please correct and submit again<br>';
}

$Descendant_First_Name = $_POST['descendant_first_name'];
$Descendant_Middle_Name = $_POST['descendant_middle_name'];
$Descendant_Surname = $_POST['descendant_surname'];
$S_SO_First_Name = $_POST['s_so_first_name'];
$S_SO_Middle_Name = $_POST['s_so_middle_name'];
$S_SO_Last_Name = $_POST['s_so_last_name'];
$Child1_First_Name = $_POST['child1_first_name'];
$Child1_Middle_Name = $_POST['child1_middle_name'];
$Child1_Last_Name = $_POST['child1_last_name'];
$Child2_First_Name = $_POST['child2_first_name'];
$Child2_Middle_Name = $_POST['child2_middle_name'];
$Child2_Last_Name = $_POST['child2_last_name'];
$Child3_First_Name = $_POST['child3_first_name'];
$Child3_Middle_Name = $_POST['child3_middle_name'];
$Child3_Last_Name = $_POST['child3_last_name'];
$Child4_First_Name = $_POST['child4_first_name'];
$Child4_Middle_Name = $_POST['child4_middle_name'];
$Child4_Last_Name = $_POST['child4_last_name'];
$Street = $_POST['street'];
$City = $_POST['city'];
$StateProvince = $_POST['stateprovince'];
$PostalCode = $_POST['postalcode'];
$Phone = $_POST['phone'];
$Email = $_POST['email'];
$Confirm = $_POST['confirm'];
$Adults = $_POST['adults'];
$Children = $_POST['children'];
$RegistrationFee = $_POST['registrationfee'];
$Comments = $_POST['comments'];

$webMaster = '<[email protected]>';

$immigrant="";
foreach($_POST["immigrant"] as $option){
   $immigrant .= $option;
}

$body = <<<EOD




Descendant_First_Name: $Descendant_First_Name

Descendant_Middle_Name: $Descendant_Middle_Name

Descendant_Surname: $Descendant_Surname

S_SO_First_Name: $S_SO_First_Name

S_SO_Middle_Name: $S_SO_Middle_Name

S_SO_Last_Name: $S_SO_Last_Name

Child1_First_Name: $Child1_First_Name

Child1_Middle_Name: $Child1_Middle_Name

Child1_Last_Name: $Child1_Last_Name

Child2_First_Name: $Child2_First_Name

Child2_Middle_Name: $Child2_Middle_Name

Child2_Last_Name: $Child2_Last_Name

Child3_First_Name: $Child3_First_Name

Child3_Middle_Name: $Child3_Middle_Name

Child3_Last_Name: $Child3_Last_Name

Child4_First_Name: $Child4_First_Name

Child4_Middle_Name: $Child4_Middle_Name

Child4_Last_Name: $Child4_Last_Name

Street: $Street

City: $City

StateProvince: $StateProvince

PostalCode: $PostalCode

Phone: $Phone

Email: $Email

Confirm: $Confirm

Descended From: $immigrant

Adults: $Adults

Children: $Children

RegistrationFee: $RegistrationFee

Comments: $Comments

EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";

/* if we got any errors echo out the error otherwise send the mail */
if($error != "") {
   echo $error;
}else{
   $success = mail($webMaster,$emailSubject,$body,$headers);
   
   echo "Your Registration has been submitted successfully. We will contact you by email and confirm your Registration within 48 hours.";
}

}else{
/* If $_POST check is false give this message */

echo "Form Submission error."; <a href='javascript:history.back(1);'>Back</a>"; 

}

?> [/php]

See if you have access to the mail logs on your host, first.
If you do, you can see if they were sent and accepted at least.

Are you sure they didn’t end up in your junk/ spam folder? mail() tends to end up there because of validation reasons, if it is accepted at all.

I am not sure how to access the mail logs, I will try to do so a little later today.

When I submit the form I get the message that the form was successfully submitted so I am assuming, whether right or wrong, that the form was sent to the php script and there was no error when running the script. But apparently the email was not generated and sent.

I forgot to mention that I have been working on the last line of code, and instead of this . . . .
echo “Form Submission error.”; Back";
}

I have this instead
echo “Form Submission error.”;
}

The first one was causing an error. I forgot to mention that in my opening post, sorry about that.

You are getting the error because:

echo “Form Submission error.”; Back";

The red item is not a concatenation symbol.

echo “Form Submission error. Back”;

Thanks for the info. I had dropped that part and just used

echo “Form Submission error.”;
}

and that seems to work. I will change it to be the one you corrected for me.

Any thoughts as to why the form doesn’t get sent to me when submitted?

Honestly, that’s why I don’t like, and haven’t used the mail function for quite some time. Phpmailer or mailgun is the route I would take, more on the latter than former.

If I were to use PHPMailer of Mailgun I suspect it would mean I have to change the form code and the PHP code, is that not correct?

I don’t mind learning new things, actually, I rather enjoy it. But I haven’t learned PHP yet, in fact, I have just scratched the surface in learning it. I would like to learn a lot more about this before I try something else.

Nobody has any idea as to why the code I have won’t send the email to me?

If your code was working before, but not now, it’s likely because your php version got updated to one that doesn’t have register globals, which would have been magically creating the $email variable from $_POST[‘email’].

The $email variable that’s being used in the mail header doesn’t exist in the posted code, resulting in an empty From: mail header, which is probably throwing a php error and returning a false value from the mail() call.

If you set php’s error_reporting to E_ALL and display_errors to ON, you will likely be getting some useful error information. Your code is assigning the return value from the mail() call to a variable, but the code isn’t using that, which it should and output some sort of relevant error message.

Next, these emails are NOT being sent from the email address that someone enters in your form. They are being sent from the mail server at your web hosting. The From: mail header must be an email address that corresponds to the sending mail server. You can put the email address that was entered in your form into a Reply-to; mail header, after validating that it is only and exactly one validly formatted email address.

If I were to use PHPMailer of Mailgun I suspect it would mean I have to change the form code and the PHP code, is that not correct?

The phpmailer class is only the interface between the php code and the sending mail server. The call to the mail() statement would be replaced with calls to phpmailer methods/properties.

I understood maybe half of what you wrote, probably not that much. I guess the idea of it is that if the PHP version on the server was updated, that would prevent the form from working. I would have thought a newer version of PHP would be compatible with the previous version, but apparently I would be wrong. If that is the case then I am not sure it pays to even bother trying to fix the form. I mean, if every time a new version of PHP comes out, depending on what was changed in the PHP code, the form code may need to be re-done again. I will have to give this some careful thought. Thanks for the information, it isn’t what I was hoping for, but I guess if that is the way it is I will have to either live with it, or forget about the form.

The issue isn’t the form. It’s some lazy and out of date (from over a decade ago) php code that relied on a feature that was DEPRECATED back in 2002 and removed in 2012. Fixing the $email variable usage (there’s a second variable $Email that could be used instead) would return the script to the state before any php version change.

I just contacted the people who run the server at iPower and they said we were using PHP version 5.5 and there has been no recent changes made to it. I asked it there was a more recent version available and was told there is and they would change it to be version 7. So as of today the PHP version will be 7. I am not sure how that affects the form I have been working on, but I guess I will soon find out.

Sponsor our Newsletter | Privacy Policy | Terms of Service