...

View Full Version : Email form(email not required fix)



hans8233
02-07-2010, 08:53 PM
Hey all-
I have the following php for a form email:
<?php
$to = "myemail@gmail.com.com" ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "RSVP";

$fields = array();
$fields{"Name"} = "Name";
$fields{"Email"} = "Email";
$fields{"RSVP"} = "RSVP";
$fields{"Message"} = "Message";

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: myemail@gmail.com";
$subject2 = "Thank you for RSVP'ing";
$autoreply = "Thank you for RSVP'ing! We hope that you checked that you were coming. We can't wait for July 24th! Kristi & Graham";

if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: http://www.mysite.com/index.html" );}
else
{print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; }
}
}
?>


It works fine as is. (it's an RSVP for my wedding). I don't want an email to be necessary though. When I take out:
if($from == '') {print "You have not entered an email, please go back and try again";} , hitting submit on my html page just takes the browser to a blank page that is .../contact.php.

How can i fix this so email isn't required, and the page is redirected towards my index?

Thanks in advance.

mlseim
02-07-2010, 09:11 PM
The "blank page" is because you have a PHP script error, and your PHP error reporting is turned-off with your webhost account.

So, I'm guessing when you remove that line you mentioned, the "else" statement needs to go too.

You might want to turn-on error reporting to get an idea of what the error is, and what line:
http://php.net/manual/en/function.error-reporting.php

thekooliest
02-08-2010, 02:27 AM
Try that...also I suggest using $_GET or $_POST instead of $_REQUEST...and echo instead of print. Ask any questions,
Sam



<?php
$to = "myemail@gmail.com.com" ;
if($_REQUEST['Email'] == '') {
$from = 'noemail@rsvp.com';
} else {
$from = $_REQUEST['Email'] ;
}
if($_REQUEST['Name'] == '') {
die("You have not entered a name, please go back and try again");
} else {
$name = $_REQUEST['Name'] ;
}
$headers = "From: $from";
$subject = "RSVP";

$fields = array();
$fields{"Name"} = "Name";
$fields{"Email"} = "Email";
$fields{"RSVP"} = "RSVP";
$fields{"Message"} = "Message";

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: myemail@gmail.com";
$subject2 = "Thank you for RSVP'ing";
$autoreply = "Thank you for RSVP'ing! We hope that you checked that you were coming. We can't wait for July 24th! Kristi & Graham";

$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: http://www.mysite.com/index.html" );}
else
{print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; }
}
}
?>

hans8233
02-10-2010, 12:24 AM
The "blank page" is because you have a PHP script error, and your PHP error reporting is turned-off with your webhost account.

So, I'm guessing when you remove that line you mentioned, the "else" statement needs to go too.

You might want to turn-on error reporting to get an idea of what the error is, and what line:
http://php.net/manual/en/function.error-reporting.php

Thanks for the responses....
I can't seem to figure out how to turn on error reporting in the code in my initial post. Any help? Thanks!

MattF
02-10-2010, 12:29 AM
Just after the opening php tag at the top of the script, add:



error_reporting(E_ALL);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum