website contact form not working
my form doesn’t work. can anyone help me?
here’s the code in the html file:
<form method="POST" action="contact2.php">
Fields marked (*) are required
<p>Email From:* <br>
<input type="text" name="EmailFrom">
<p>FirstName:<br>
<input type="text" name="FirstName">
<p>LastName:<br>
<input type="text" name="LastName">
<p>HomeTel:<br>
<input type="text" name="HomeTel">
<p><input type="submit" name="submit" value="Submit">
</form>
and here’s the php file:
<?php
$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
$EmailTo = "";
$Subject = "Testing";
$FirstName = Trim(stripslashes($_POST['FirstName']));
$LastName = Trim(stripslashes($_POST['LastName']));
$HomeTel = Trim(stripslashes($_POST['HomeTel']));
// validation
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (!$validationOK) {
print "<meta http-equiv="refresh" content="0;URL=error.html">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "FirstName: ";
$Body .= $FirstName;
$Body .= "n";
$Body .= "LastName: ";
$Body .= $LastName;
$Body .= "n";
$Body .= "HomeTel: ";
$Body .= $HomeTel;
$Body .= "n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv="refresh" content="0;URL=ok.html">";
}
else{
print "<meta http-equiv="refresh" content="0;URL=error.html">";
}
?>
Is any variables being passed? What do you mena by NOT working?
Not sure the difference between php and perl, but in perl if you do $EmailTo = "blah@blah.com" you would have to escape the @ to prevent it from referencing the array @blah, so it would have to be "blah@blah.com" – if it seems to work but you’re not getting an e-mail, check that. Other than that I don’t do PHP really, and you’ll need to provide a lot more detail than "it doesn’t work". What part seems to be failing, have you tried debugging statements and printing them to the browser, etc.
.
Need a little more information.
PHP doesn’t mind the @ symbol being in the "s.
when i click submit it goes to the php page and spits this out:
"; exit; } // prepare email body text $Body = ""; $Body .= "FirstName: "; $Body .= $FirstName; $Body .= "n"; $Body .= "LastName: "; $Body .= $LastName; $Body .= "n"; $Body .= "HomeTel: "; $Body .= $HomeTel; $Body .= "n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print ""; } else{ print ""; } ?>
Based on that, I’m guessing
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
should be
$validationOK=true;
if (Trim($EmailFrom)=="") { $validationOK=false; }
looks good to me. if it’s spitting out actual php code your server set up may be the problem.
|
Based on that, I’m guessing
$validationOK=true; should be $validationOK=true; |
that shouldn’t make a difference.
Sounds like when you FTP’d it something went wrong. Try uploading again.
|
looks good to me. if it’s spitting out actual php code your server set up may be the problem.
that shouldn’t make a difference. |
Uh…why wouldn’t the braces make a difference? He has a very similar if statement directly below that one that does have the braces. If its not required, why put braces after one if statement but not after the other if statement? Its either wrong, or just bad coding.
Edit: to show what i meant
No braces:
if (Trim($EmailFrom)=="") $validationOK=false;
Braces:
if (!$validationOK) {
print "<meta http-equiv="refresh" content="0;URL=error.html">";
exit;
}
Why is it ok on the first one but not the second one? Languages are typically very very picky about where you have braces, and if PHP doesn’t care whether you have braces to enclose the block of code from an if statement thats just shitty.
Its ok because one if statement executes one command, and the other executes multiple commands.
Edit: Its the same in C, C++, Java, and 11ty billion other languages.
|
Its ok because one if statement executes one command, and the other executes multiple commands.
Edit: Its the same in C, C++, Java, and 11ty billion other languages. |
and perl. in fact in perl with 1 line ‘if’ statements you can even put it before the condition like this:
$num = 1 if $num >1;
Weird.
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.