Note that there are some explanatory texts on larger screens.

plurals
  1. POMy PHP Script is not processing correctly (new to PHP)
    primarykey
    data
    text
    <p>I tried to write a PHP script to automatically send an email with form inputs, but when it is called upon on submit, it is displaying the error I put in if you try to access the php directly.</p> <p>Any help would be greatly appreciated, I am very new at this.</p> <pre><code>&lt;form action="form-to-email.php" method="post" name="camper_registration" id="camper registration" "&gt; &lt;label&gt;Last Name*: &lt;/label&gt; &lt;input name="lastname" type="text" id="lastname" required="required"/&gt;&lt;br /&gt; &lt;label&gt;First Name*: &lt;/label&gt; &lt;input name="firstname" type="text" id="firstname" required="required"/&gt;&lt;br /&gt; &lt;label&gt;Middle Initial: &lt;/label&gt; &lt;input type="text" name="initial" size=1 maxlength=1 /&gt;&lt;br /&gt;&lt;br /&gt; &lt;label&gt;Street Address*: &lt;/label&gt; &lt;input name="streetaddress" type="text" id="streetaddress" required="required"/&gt;&lt;br /&gt; &lt;label&gt;Address Line 2: &lt;/label&gt;&lt;input type="text" name="addressline2" /&gt;&lt;br /&gt; &lt;label&gt;City*: &lt;/label&gt; &lt;input name="city" type="text" id="city" required="required"/&gt;&lt;br /&gt; &lt;label&gt;State/Province/Region*: &lt;/label&gt; &lt;input name="state" type="text" id="state" required="required"/&gt;&lt;br /&gt; &lt;label&gt;Zipcode*: &lt;/label&gt; &lt;INPUT NAME="zip" input type="tel" SIZE=5 MAXLENGTH=5 onKeyPress="return numbersonly(this, event)" required="required"&gt;&lt;br /&gt;&lt;br /&gt; &lt;label&gt;Youth's Email*: &lt;/label&gt; &lt;input type="email" name="email" required="required"/&gt;&lt;br /&gt;&lt;br /&gt; &lt;label&gt;Date of Birth*: &lt;/label&gt; &lt;INPUT NAME="month" input type="tel" SIZE=2 MAXLENGTH=2 onKeyPress="return numbersonly(this, event)" required="required"&gt;/ &lt;INPUT NAME="day" input type="tel" SIZE=2 MAXLENGTH=2 onKeyPress="return numbersonly(this, event)" required="required"&gt;/ &lt;INPUT NAME="year" input type="tel" SIZE=4 MAXLENGTH=4 onKeyPress="return numbersonly(this, event)" required="required"&gt; &lt;SCRIPT TYPE="text/javascript"&gt; autojump("month", "day", 2); autojump("day", "year", 2); &lt;/SCRIPT&gt; &lt;br /&gt;&lt;br /&gt; &lt;label&gt;Grade completed in&lt;br /&gt; Spring 2013*: &lt;/label&gt; &lt;input type="tel" name="grade" size=2 maxlength=2 required="required"/&gt;&lt;br /&gt;&lt;br /&gt; &lt;label&gt;Gender*:&lt;/label&gt; &lt;input type="radio" name="gender" value="Male" required="required"&gt; Male &lt;input type="radio" name="gender" value="Female" required="required"&gt; Female &lt;br /&gt; &lt;br /&gt; &lt;label&gt;Parent/Guardian(s)*: &lt;/label&gt; &lt;input name="guardian" type="text" id="guardian" required="required"/&gt; &lt;br /&gt;&lt;br /&gt; &lt;label&gt;Parent Phone*: &lt;/label&gt; (&lt;INPUT NAME="areacode" input type="tel" SIZE=3 MAXLENGTH=3 onKeyPress="return numbersonly(this, event)" required="required"&gt;) &lt;INPUT NAME="cellphone" input type="tel" SIZE=7 MAXLENGTH=7 onKeyPress="return numbersonly(this, event)" required="required"&gt;&lt;br /&gt;&lt;br /&gt; &lt;SCRIPT TYPE="text/javascript"&gt; &lt;!-- autojump("areacode", "cellphone", 3); //--&gt; &lt;/SCRIPT&gt; &lt;label&gt;1st Emergency Contact*: &lt;/label&gt; &lt;input name="emergency_contact_1" type="text" id="emergency_contact_1" required="required"/&gt;&lt;br /&gt;&lt;br /&gt; &lt;label&gt;Contact Number*: &lt;/label&gt; (&lt;INPUT NAME="emergency_contact_1_areacode" input type="tel" SIZE=3 MAXLENGTH=3 onKeyPress="return numbersonly(this, event)" required="required"&gt;) &lt;INPUT NAME="emergency_contact_1_phone" input type="tel" SIZE=7 MAXLENGTH=7 onKeyPress="return numbersonly(this, event)" required="required"&gt;&lt;br /&gt;&lt;br /&gt; &lt;SCRIPT TYPE="text/javascript"&gt; &lt;!-- autojump("emergency_contact_1_areacode", "emergency_contact_1_phone", 3); //--&gt; &lt;/SCRIPT&gt; &lt;label&gt;2nd Emergency Contact*: &lt;/label&gt; &lt;input name="emergency_contact_2" type="text" id="emergency_contact_2" required="required"/&gt;&lt;br /&gt;&lt;br /&gt; &lt;label&gt;Contact Number*: &lt;/label&gt; (&lt;INPUT NAME="emergency_contact_2_areacode" input type="tel" SIZE=3 MAXLENGTH=3 onKeyPress="return numbersonly(this, event)" required="required"&gt;) &lt;INPUT NAME="emergency_contact_2_phone" input type="tel" SIZE=7 MAXLENGTH=7 onKeyPress="return numbersonly(this, event)" required="required"&gt;&lt;br /&gt;&lt;br /&gt; &lt;SCRIPT TYPE="text/javascript"&gt; &lt;!-- autojump("emergency_contact_2_areacode", "emergency_contact_2_phone", 3); //--&gt; &lt;/SCRIPT&gt; &lt;label&gt;Name of Home Church: &lt;/label&gt; &lt;input type="text" name="home_church" /&gt;&lt;br /&gt;&lt;br /&gt; &lt;label&gt;Phone Number: &lt;/label&gt; (&lt;INPUT NAME="church_areacode" input type="tel" SIZE=3 MAXLENGTH=3 onKeyPress="return numbersonly(this, event)"&gt;) &lt;INPUT NAME="church_phone" input type="tel" SIZE=7 MAXLENGTH=7 onKeyPress="return numbersonly(this, event)"&gt;&lt;br /&gt; &lt;SCRIPT TYPE="text/javascript"&gt; autojump("church_areacode", "church_phone", 3); &lt;/SCRIPT&gt; &lt;label&gt;Contact Person: &lt;/label&gt; &lt;input type="text" name="contact_person" /&gt;&lt;br /&gt;&lt;br /&gt; &lt;b&gt;Special Needs&lt;/b&gt;&lt;br /&gt; Some campers may have needs that might require special attention from our staff; accessibility, health concerns, diet, allergies, etc. &lt;br /&gt;&lt;br /&gt; &lt;label&gt;Please list any special needs: &lt;/label&gt; &lt;textarea rows="10" cols="20" name="special_needs"&gt; &lt;/textarea&gt; &lt;br /&gt;&lt;br /&gt; &lt;label&gt;T-Shirt Size*: &lt;/label&gt; &lt;input type="radio" name="shirt_size" value="Small" required="required"&gt; Small &lt;input type="radio" name="shirt size" value="Medium" required="required"&gt; Medium &lt;input type="radio" name="shirt size" value="Large" required="required"&gt; Large &lt;input type="radio" name="shirt size" value="XL" required="required"&gt; XL &lt;input type="radio" name="shirt size" value="2XL" required="required"&gt; 2XL&lt;br /&gt;&lt;br /&gt; &lt;b&gt;Roommate&lt;/b&gt;&lt;br /&gt; There are double and many single occupancy dorm rooms at Grinnell college campus - if possible we will honor your request for ONE preferred roommate.&lt;br /&gt;&lt;br /&gt; &lt;label&gt;Roommate Preference: &lt;/label&gt; &lt;input type="text" name="roommate" /&gt;&lt;br /&gt;&lt;br /&gt; &lt;div id="satellites"&gt; &lt;b&gt;Satellite Choices&lt;/b&gt;&lt;br /&gt; List your first, second, and third choices. You will be given your first choice if it is not full. ALL events have limited capacity. If you do not choose a satellite, one will be assigned for you. (&lt;a href="satellites.htm"target="_blank"&gt;Satellite Choices&lt;/a&gt;)&lt;br /&gt; &lt;label&gt;First Choice*: &lt;/label&gt; &lt;input name="firstchoice" type="text" id="firstchoice" required="required"/&gt;&lt;br /&gt; &lt;label&gt;Second Choice*: &lt;/label&gt; &lt;input name="secondchoice" type="text" id="secondchoice" required="required"/&gt;&lt;br /&gt; &lt;label&gt;Third Choice*: &lt;/label&gt; &lt;input name="thirdchoice" type="text" id="thirdchoice" required="required"/&gt;&lt;br /&gt;&lt;br /&gt; &lt;/div&gt; &lt;p&gt; &lt;b&gt; Remember! &lt;/b&gt;&lt;br /&gt;Please to fill out and bring the &lt;a href="Camper_Health_History_and_Authorization_Form_2013.pdf"&gt;Health Form&lt;/a&gt; &lt;i&gt;with you to camp&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt; &lt;b&gt;Cost of SGU Camp July 8 - 12, 2013 $275 &lt;br /&gt;&lt;/b&gt; A $50 &lt;i&gt; non-refundable&lt;/i&gt; fee is required to be registered. &lt;br /&gt; Due to the limited capacity of 400 campers, please note full payment is due by June 25th to ensure you have completed the registration process. &lt;/p&gt;&lt;br /&gt; &lt;input type="submit" value="Submit"&gt; &lt;/form&gt; </code></pre> <p>And here is the PHP</p> <pre><code>&lt;?php if(!isset($_POST['submit'])){ //This page should not be accessed directly. Need to submit the form. echo "error; you need to submit the form!"; die; } $page = "camper.htm"; if (!ereg($page, $_SERVER['HTTP_REFERER'])){ echo "Invalid referer"; die; } $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $initial = $_POST['initial']; $streetaddress = $_POST['streetaddress']; $addressline2 = $_POST['addressline2']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; $email = $_POST['email']; $month = $_POST['month']; $day = $_POST['day']; $year = $_POST['year']; $grade = $_POST['grade']; $gender = $_POST['gender']; $guardian = $_POST['guardian']; $areacode = $_POST['areacode']; $cellphone = $_POST['cellphone']; $contact1 = $_POST['emergency_contact_1']; $contact1areacode = $_POST['emergency_contact_1_areacode']; $contact1phone = $_POST['emergency_contact_1_phone']; $contact2 = $_POST['emergency_contact_2']; $contact2areacode = $_POST['emergency_contact_2_areacode']; $contact2phone = $_POST['emergency_contact_2_phone']; $homechurch = $_POST['home_church']; $churchareacode = $_POST['church_areacode']; $churchphone = $_POST['church_phone']; $contactperson = $_POST['contact_person']; $specialneeds = $_POST['special_needs']; $shirtsize = $_POST['shirt_size']; $roommate = $_POST['roommate']; $firstchoice = $_POST['firstchoice']; $secondchoice = $_POST['secondchoice']; $thirdchoice = $_POST['thirdchoice']; //Validate first if(IsInjected($visitor_email)){ echo "Bad email address!"; exit; } /* Simple form validation check to see if an email and message were entered */ if ($_POST['firstname'] == "" || $_POST['lastname'] == "" || $_POST['streetaddress'] == "" || $_POST['city'] == "" || $_POST['state'] == "" || $_POST['zip'] == "" || $_POST['email'] == "" || $_POST['month'] == "" || $_POST['day'] == "" || $_POST['year'] == "" || $_POST['grade'] == "" || $_POST['gender'] == "" || $_POST['guardian'] == "" || $_POST['areacode'] == "" || $_POST['cellphone'] == "" || $_POST['emergency_contact_1'] == "" || $_POST['emergency_contact_1_areacode'] == "" || $_POST['emergency_contact_1_phone'] == "" || $_POST['emergency_contact_2'] == "" || $_POST['emergency_contact_2_areacode'] == "" || $_POST['emergency_contact_2_phone'] == "" || $_POST['shirt_size'] == "" || $_POST['firstchoice'] == "" || $_POST['secondchoice'] == "" || $_POST['thirdchoice'] == "" ) { echo "Please fill in all required boxes."; } else { $email_from = 'cscholtens@marionmethodist.org';//&lt;== update the email address $email_subject = "New Registration"; $email_body = "You have received a new registration.\n". "Camper: $firstname $initial $lastname \n". "Address: $streetaddress \n". "$addressline2 \n". "$city, $state $zip \n". "Email: $email \n". "Date of Birth: $month/$day/$year \n". "Grade Completed: $grade \n". "Gender: $gender \n". "Guardian: $guardian \n". "Guardian Cell Phone: ($areacode) $cellphone \n". "First Emergency Contact: $contact1 Contact Number: ($contact1areacode) $contact1phone \n". "Second Emergency Contact: $contact2 Contact Number: ($contact2areacode) $contact2phone \n". "Home Church: $homechurch Contact Number: ($churchareacode) $churchphone Contact Person: $contactperson \n". "Special Needs: $specialneeds \n". "T-Shirt Size: $shirtsize \n". "Roommate Preference: $roommate \n". "Satellite Preferences: 1.$firstchoice 2.$secondchoice 3.$thirdchoice \n". " \n". $to = "cscholtens@marionmethodist.org";//&lt;== update the email address $headers = "From: $email_from \r\n"; //Send the email! mail($to,$email_subject,$email_body,$headers); //done. redirect to thank-you page. header('Location: thanks2.htm'); // Function to validate against any email injection attempts function IsInjected($str) { $injections = array('(\n+)', '(\r+)', '(\t+)', '(%0A+)', '(%0D+)', '(%08+)', '(%09+)' ); $inject = join('|', $injections); $inject = "/$inject/i"; if(preg_match($inject,$str)){ return true; } else{ return false; } } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload