Topic: form redirect working but still getting blank email (Read 799 times)
My Name is Enigo Montoya
Posts: 33
188 credits Members referred : 0
« on: Dec 22, 2006, 12:58:36 pm »
I have a form which validates info and the action points to another processing page. method="POST" (although it probably wouldn't happen much, I wanted to avoid direct calls to the processing page itself). I was trying to implement the following, and was thinking along the lines of an if/else statement. First I tried...
Code:
<?php if (!isset($_SERVER['REQUEST_METHOD']) || $_SERVER['REQUEST_METHOD'] != 'POST') { header("Location: index.php?page=contact"); } ?> <?php MAIL SCRIPT CODE HERE ?>
then...
Code:
<?php if (!isset($_SERVER['REQUEST_METHOD']) || $_SERVER['REQUEST_METHOD'] != 'POST') { header("Location: index.php?page=contact"); } else $email = "$email"; //other defined variables here //email the user! $message = " name: $name email: $email subject: $subject sent with $priority priority Their message: $message ";
both work to redirect the user back to the form since they are pretty much the same, but I still get a blank email when the page is accessed directly. When the form is used properly all info is sent correctly. Does anyone see something that I am missing? It is early morning Thank you!
Global Moderator
Internet Junkie
Gender:
Posts: 1807
9006 credits Members referred : 6
« Reply #1 on: Dec 22, 2006, 01:07:27 pm »
Looks like you forgot to put the whole code after the else statement between { and } you are now having the e-mail code execute every time instead of depending on the outcome of the if statement.
Does the e-mailing work? I think you have to fill the variables like this:
$name = $_POST['name'];
where the last part is the same name as the field name in your form.
My Name is Enigo Montoya
Posts: 33
188 credits Members referred : 0
« Reply #3 on: Dec 22, 2006, 03:41:33 pm »
Changing my if statement to this worked like a charm! Thank you Nikolas, I was sort of on the right track but I probably would have never guessed that syntax.
Code:
if (count($_POST) == 0) { header("Location: index.php?page=contact"); exit; }
Mind_nl you are totally right...I have used your method in projects before where I have submitted fields to a database. $name = $_POST['name']; $email = $_POST['email']; etc
The email works to send the info submitted in the form fields. There may be another way to do this, but I guess since $message is sent to the email and the field $vars are included in it they are sent to the specified email address. For instance: sent with $priority priority - would produce as you could imagine...sent with urgent priority...with urgent being selected in the dropdown box. Thank you both again.
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=5358