My first PHP script - what's wrong with it?

Hudba

New Member
I just made my first PHP script, but there must be a mistake in it.
Could any of you please take a look at it and tell me what is wrong?
When the script executes it is supposed to send me an email with the information somebody filled out in a form on my website (first name, last name, zip code and email).
The thank you and error pages do show up when somebody tries to fill out the form, but I never get an email.
Any ideas for this newbie?:confused:
PHP:
<?

$mailto = "filled in my email address here" ;


$subject = "newsletter sign up" ;



$formurl = "http://my URL/newsletter.html" ;
$errorurl = "http://my URL/newslettererror.html" ;
$thankyouurl = "http://my URL/thankyounewsletter.html" ;


$first_name = $_POST['first_name'] ;
$last_name = $_POST['last_name'] ;
$zip_code = $_POST['zip_code'] ;
$email = $_POST['email'] ;
$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {
	header( "Location: $formurl" );
	exit ;
}
if (empty($first_name) || empty($last_name) || empty($zip_code) || empty($email)) {
   header( "Location: $errorurl" );
   exit ;
}
$first_name = strtok( $first_name, "\r\n" );
$last_name = strtok( $last_name, "\r\n" );
$zip_code = strtok( $zip_code, "\r\n" );
$email = strtok( $email, "\r\n" );



mail($mailto, $subject);
header( "Location: $thankyouurl" );
exit ;

?>
 

drummondjacob

New Member
The mail() function only works on a UNIX-based server. If you're using a Windiws machine then it won't work. Generally it's not a problem because generally the web server you actually use is UNIX based
 

thunderburung

New Member
HI, you just forgot to put one of the three "must have" parameter inorder to send the mail.

Your code should be like this
mail($mailto, $subject,$message);

Where $message is the content of the email.
 
Top