28, May 2012

form redirect working but still getting blank email - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: form redirect working but still getting blank email
« previous next »
Pages: [1] Print
Instabuck - The easy way to sell digital products online

Author 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
"
;

mail('you@yourdomain.com'$message"From: $name <$email>\nX-Mailer: PHP/" phpversion());
?>
  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 Cheesy  Thank you!
Global Moderator
Internet Junkie
*****
Gender: Male
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.


Last blog : Are You Stumbling Yet?
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #2 on: Dec 22, 2006, 01:43:41 pm »

This code will work only with registered globals = on Smiley

Now to make this work as you want, replace this :

if (!isset($_SERVER['REQUEST_METHOD']) || $_SERVER['REQUEST_METHOD'] != 'POST') {
        
header("Location: index.php?page=contact");
    } 
?>


with this :


if (count($_POST) == 0) {
        
header("Location: index.php?page=contact");
        exit;
    } 
?>


The exit is needed because even that the header() will redirect the user, the script will continue running.

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
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! Smiley  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
Tags : form processing redirect Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: form redirect working but still getting blank email
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 28, 2012, 07:16:16 pm





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!






Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2012 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.