HTML Form to PHP Email Help

Hey guys so this is my first post on this forum and I hope im in the write section :-X, anyway I’m in a programming class in high school and my teacher likes to challenge me and my friends who are in the class because we are a little more experienced in the way of programming… Anyway we are currently learning html… (I know, we are learning html in a PROGRAMMING class so not what I had in mind, but anyway) He gave us a picture of a pretty big form to re create from scratch, which is not the hard part. I figured I’d actually make it work. I already have experience posting the data to MySQL tables so i figured it would be a cool idea to make it send an email to a set email with some data. Every time i submit it i get this error; not even a PHP syntax error…

"We are very sorry, but there were error(s) found with the form you submitted. These errors appear below.

We are sorry, but there appears to be a problem with the form you submitted.

Please go back and fix these errors."

Mind you, the email script is not mine, I found it on some site, but im trying to edit it to work with my form. I have basically hit a brick wall here.

Anyway here is my PHP

[php]

<?php if(isset($_POST['E-Mail'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "[email protected]"; $email_subject = "Form Submission"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.

"; echo $error."

"; echo "Please go back and fix these errors.

"; die(); } // validation expected data exists if(!isset($_POST['First Name']) || !isset($_POST['Last Name']) || !isset($_POST['E-Mail']) || !isset($_POST['Year']) || !isset($_POST['other'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['First Name']; // required $last_name = $_POST['Last Name']; // required $email_from = $_POST['E-Mail']; // required $year = $_POST['Year']; // not required $comments = $_POST['other']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.
'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.
'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.
'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Year Of Graduation: ".clean_string($year)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($email_to, $email_subject, $email_message, $headers); ?>

Thank you for contacting us. We will be in touch with you very soon.

<?php } ?>

[/php]

And my Form

<!DOCTYPE html>
<html lang="en-US">

<head>
<title>Obelisk Yearbook Club Signup</title>
<body bgcolor="#900">
<div align="center">
<img src="http://www.rexl.net/logo3.png" width="200" height="200" alt="wildcat logo"><br />
</div>
<h1 align="center">Obelisk Yearbook Club</h1><br />
<h2 align="center">Application</h2><br />
<h3 align="center">2014</h3>
<form name="obelisksignup" action="send_form_email.php" method="post">
<fieldset>
    <legend>About</legend>
        <table>
            <tr><td>First Name:</td><td><input type="text" name="First Name"></td><br />
            </tr>
            <tr>
            <td>Last Name:</td><td><input type="text" name="Last Name"></td><br />
            </tr>
            <tr>
            <td>E-Mail:</td><td><input type="text" name="E-Mail" size="40"></td><br />
            </tr>
            <br />
        </table>
    Graduation Year<input type="radio" name="Year" value="2014"> 2014<input type="radio" name="Year" value="2015"> 2015<input type="radio" name="Year" value="2016"> 2016<input type="radio" name="Year" value="2017"> 2017
</fieldset>
<br />
<br />
<fieldset>
    <legend>Sports</legend>
    Please select any sports that you plan to be involved in this year:<br />
        <table width="400">
        <tr>
        <td><b>Fall Sports</b></td><td><b>Winter Sports</td><td><b>Spring Sports</b><td>
        </tr>
        <br />
        <tr><td><input type="checkbox" name="sport">Cheerleading</td><td><input type="checkbox" name="sport">Basketball</td><td><input type="checkbox" name="sport">Baseball</td> </tr>
        <tr><td><input type="checkbox" name="sport">Cross Country</td><td><input type="checkbox" name="sport">Bowling</td><td><input type="checkbox" name="sport">Golf</td> </tr>
        <tr><td><input type="checkbox" name="sport">Field Hockey</td><td><input type="checkbox" name="sport">Cheerleading</td><td><input type="checkbox" name="sport">Lacrosse(Boys)</td> </tr>
        <tr><td><input type="checkbox" name="sport">Football</td><td><input type="checkbox" name="sport">Ice Hockey</td><td><input type="checkbox" name="sport">Softball</td> </tr>
        <tr><td><input type="checkbox" name="sport">Soccer</td><td><input type="checkbox" name="sport">Swimming</td><td><input type="checkbox" name="sport">Tennis (Boys)</td> </tr>
        <tr><td><input type="checkbox" name="sport">Tennis (Girls)</td><td><input type="checkbox" name="sport">Weightlifting</td><td><input type="checkbox" name="sport">Track & Field</td> </tr>
        <tr><td><input type="checkbox" name="sport">Weightlifting</td><td><input type="checkbox" name="sport">Wrestling</td><td><input type="checkbox" name="sport">Weightlifting</td> </tr>
        </table>
</fieldset>
<br />
<br />
<fieldset>
    <legend>Clubs and Organizations</legend>
    Please select any clubs or organizations that you plan to be involved in this year:
        <table>
        <tr><td><b>Literary</b></td><td><b>Music</b></td><td><b>Preforming Arts<b></td><td><b>Service</b></td><td><b>Special Interest</b></tr><br />
        <tr><td><input type="checkbox" name="club">Calliope</td><td><input type="checkbox" name="club">Chamber Singers</td><td><input type="checkbox" name="club">Fall Production</td><td><input type="checkbox" name="club">Key Club</td><td><input type="checkbox" name="club">Academic Bowl</td></tr>
        <tr><td><input type="checkbox" name="club">Monument</td><td><input type="checkbox" name="club">Jazz Ensemble</td><td><input type="checkbox" name="club">Spring Musical</td><td><input type="checkbox" name="club">National Honors Society</td><td><input type="checkbox" name="club">DECA</td></tr>
        <tr><td><input type="checkbox" name="club">Obelisk</td><td><input type="checkbox" name="club">Marching Band</td><td rowspan="8"></td><td><input type="checkbox" name="club">Pride</td><td><input type="checkbox" name="club">Engineering & Design</td></tr>
        <tr><td rowspan="7"></td><td rowspan="7"></td><td><input type="checkbox" name="club">Peer Counseling</td><td><input type="checkbox" name="club">FBLA</td></tr>
        <tr><td><input type="checkbox" name="club">SAVE</td><td><input type="checkbox" name="club">Game Club</td></tr>
        <tr><td><input type="checkbox" name="club">Student Council</td><td><input type="checkbox" name="club">International Club</td></tr>
        <tr><td><input type="checkbox" name="club">World Language National Honors Society</td><td><input type="checkbox" name="club">Mock Trial</td></tr>
        <tr><td rowspan="3"></td><td><input type="checkbox" name="club">Science Olympiad</td></tr>
        <tr><td><input type="checkbox" name="club">Technology Student Association</td></tr>
        <tr><td><input type="checkbox" name="club">Weight Lifting</td></tr>
        </table>
</fieldset>
<br />
<br />
<fieldset>
    <legend>Skills</legend>
    Which areas do you feel you already have experience in?
        <table>
        <tr><td><input type="checkbox" name="skill">Photography</td><td><input type="checkbox" name="skill">Photoshop</td></tr>
        <tr><td><input type="checkbox" name="skill">Writing</td><td><input type="checkbox" name="skill">Page Layout</td></tr>
        <tr><td><input type="checkbox" name="skill">Editing</td><td><input type="checkbox" name="skill">Illustration</td></tr>
        </table>
</fieldset>
<br />
<br />
<fieldset>
    <legend>Interests</legend>
    Which area would you most like to learn about?<br />
        <select>
            <option value="layout">Layout</option>
            <option value="dan1">Dan</option>
            <option value="dan2">Dan</option>
            <option value="dan3">Dan</option>
        </select>
    How do you work best?<br />
    <br />
    <input type="radio" name="group" value="Large">Large Groups<input type="radio" name="group" value="Small">Small Groups<input type="radio" name="group" value="alone">Alone
</fieldset>
<br />
<br />
<fieldset>
    <legend>Other</legend>
    Please list any other skills, interests, or availability concerns you have.<br />
    <textarea name="other" cols="100" rows="7"></textarea>
</fieldset>
<br />
<br />
<fieldset>
    <legend>Complete</legend>
    After you submit this form, please allow one week for us to respond to you via the e-mail address you provided. Thank you for your interest.<br />
    <br />
    <input type="submit" value="Submit">
</fieldset>
</form>
</body>

</html>
</head>

I would greatly appreciate any help to find this problem.

Thanks, Ed

You should add the following to your php files while developing, it will give you all errors and warnings

[php]ini_set(‘error_reporting’, E_ALL);
ini_set(‘display_errors’, ‘1’);[/php]

[hr]

First off, the html in your form is invalid, you should move the closing head tag up quite a few lines… :wink:

[hr]

PHP

You have an unexpected end of file, since you never close the first if condition.

[hr]

Do you have a custom function called “died”? The similar function included in PHP is called “die”

[hr]

When assigning form values you should add a default / failsafe, like this:
[php]$first_name = !empty($_POST[‘First Name’]) ? $_POST[‘First Name’] : ‘Not submitted’;[/php]

[hr]

Regular expressions are slow, is it part of the assignment? If not you could use the much easier to read and faster php validate filters
http://php.net/manual/en/filter.filters.validate.php

[hr]

Blacklists are generally considered bad practice. Consider changing to another mail library to get proper escaping of email headers.

Sponsor our Newsletter | Privacy Policy | Terms of Service