Forum Moderators: coopster

Message Too Old, No Replies

E-mailing HTML form info with PHP

         

martizzle

6:43 pm on Jan 13, 2006 (gmt 0)

10+ Year Member



I followed the code given on this site for e-mail HTML form information with PHP and it works with the exception of the error msg's. I followed the code and read it over several times but cannot see where my mistake is. The following is my code I am using:
<?php
$errmsg = "";
if (!isset($_POST['Student_name']) ¦¦ empty($_POST['Student_name'])) $errmsg .= "<p>Please enter your first name";
if (!isset($_POST['Student_birthday']) ¦¦ empty($_POST['Student_birthday'])) $errmsg .= "<p>Please enter your birthday";
if (!isset($_POST['Student_graduation']) ¦¦ empty($_POST['Student_graduation'])) $errmsg .= "<p>Please enter your graduation year";
if (!isset($_POST['Student_address']) ¦¦ empty($_POST['Student_address'])) $errmsg .= "<p>Please enter your address";
if (!isset($_POST['Student_city']) ¦¦ empty($_POST['Student_city'])) $errmsg .= "<p>Please enter your city";
if (!isset($_POST['Student_state']) ¦¦ empty($_POST['Student_state'])) $errmsg .= "<p>Please enter your State";
if (!isset($_POST['Student_zip']) ¦¦ empty($_POST['Student_zip'])) $errmsg .= "<p>Please enter your zip code";
if (!isset($_POST['Student_phone']) ¦¦ empty($_POST['Student_phone'])) $errmsg .= "<p>Please enter your phone number";
if (!isset($_POST['Student_email']) ¦¦ empty($_POST['Student_email'])) $errmsg .= "<p>Please enter your e-mail address";
if (!isset($_POST['Church_name']) ¦¦ empty($_POST['Church_name'])) $errmsg .= "<p>Please enter your church name";
if (!isset($_POST['Church_contact']) ¦¦ empty($_POST['Church_contact'])) $errmsg .= "<p>Please enter your Youth Pastors/contacts number";
if (!isset($_POST['Church_address']) ¦¦ empty($_POST['Church_address'])) $errmsg .= "<p>Please enter your church address";
if (!isset($_POST['Church_city']) ¦¦ empty($_POST['Church_city'])) $errmsg .= "<p>Please enter your church city";
if (!isset($_POST['Church_state']) ¦¦ empty($_POST['Church_state'])) $errmsg .= "<p>Please enter your church state";
if (!isset($_POST['Church_zip']) ¦¦ empty($_POST['Church_zip'])) $errmsg .= "<p>Please enter your church zip code";
if (!isset($_POST['question_1']) ¦¦ empty($_POST['question_1'])) $errmsg .= "<p>Please answer question 1";
if (!isset($_POST['question_2']) ¦¦ empty($_POST['question_2'])) $errmsg .= "<p>Please answer question 2";
if (!isset($_POST['question_3']) ¦¦ empty($_POST['question_3'])) $errmsg .= "<p>Please answer question 3";
if (!isset($_POST['question_4']) ¦¦ empty($_POST['question_4'])) $errmsg .= "<p>Please answer question 4";
if (!isset($_POST['question_5']) ¦¦ empty($_POST['question_5'])) $errmsg .= "<p>Please answer question 5";
if (!isset($_POST['question_6']) ¦¦ empty($_POST['question_6'])) $errmsg .= "<p>Please answer question 6";
if (!isset($_POST['question_7']) ¦¦ empty($_POST['question_7'])) $errmsg .= "<p>Please answer question 7";
if ($errmsg == "") {
echo $errmsg;
echo "<a href=\"javascript:history.back();\">Please go back and fill out the missing fields</a>";
exit;
} else {

$to = "myemail@myaddress.com";
$subject = "Student Registration";
$headers .= "Yli Registration Form\r\n";
$message = "New Student Registration!\n\n";
$message .= "Student Name: " . $_POST['Student_name'] . "\n";
$message .= "Student Birthday: " . $_POST['Student_birthday'] . "\n";
$message .= "Student Graduation Year: " . $_POST['Student_graduation'] . "\n";
$message .= "Student Address: " . $_POST['Student_address'] . "\n";
$message .= "Student City: " . $_POST['Student_city'] . "\n";
$message .= "Student State: " . $_POST['Student_state'] . "\n";
$message .= "Student Zip: " . $_POST['Student_zip'] . "\n";
$message .= "Student Phone Number: " . $_POST['Student_phone'] . "\n";
$message .= "Student E-mail: " . $_POST['Student_email'] . "\n";
$message .= "Church Name: " . $_POST['Church_name'] . "\n";
$message .= "Church Contact: " . $_POST['Church_contact'] . "\n";
$message .= "Church Phone Number: " . $_POST['Church_number'] . "\n";
$message .= "Church Address: " . $_POST['Church_address'] . "\n";
$message .= "Church City: " . $_POST['Church_city'] . "\n";
$message .= "Church State: " . $_POST['Church_state'] . "\n";
$message .= "Church Zip Code: " . $_POST['Church_zip'] . "\n";
$message .= "Sports Interests: " . $_POST['Interest_sport'] . "\n";
$message .= "Music Interests: " . $_POST['Interest_music'] . "\n";
$message .= "Art Interests: " . $_POST['Interest_art'] . "\n";
$message .= "Hobbies: " . $_POST['Interest_hobby'] . "\n";
$message .= "Question 1: " . $_POST['question_1'] . "\n";
$message .= "Question 2: " . $_POST['question_2'] . "\n";
$message .= "Question 3: " . $_POST['question_3'] . "\n";
$message .= "Question 4: " . $_POST['question_4'] . "\n";
$message .= "Question 5: " . $_POST['question_5'] . "\n";
$message .= "Question 6: " . $_POST['question_6'] . "\n";
$message .= "Question 7: " . $_POST['question_7'] . "\n";
if (mail($to,$subject,$message,$headers)) {
echo "<p>Thank you for Registering for the YLI Conference!";
} else {
echo "<p>email could not be sent";
}
}
?>

If the person doesn't fill out all the info it still sends. The error msg's don't come up.

[edited by: jatar_k at 6:48 pm (utc) on Jan. 13, 2006]
[edit reason] no urls thanks [/edit]

jatar_k

6:49 pm on Jan 13, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld martizzle,

your case is

if ($errmsg == "") {

you have it backwards, it should be

if ($errmsg!= "") {

martizzle

7:12 pm on Jan 13, 2006 (gmt 0)

10+ Year Member



THANK YOU SO MUCH! You rock!

Brian Martini