SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2012
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    my php form throws the error up and no email delivered

    Ideas would be most welcome



    <?php
    if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "test@test.co.uk";
    $email_subject = "Story Submission";


    function died($error) {
    //error code can go here
    echo "We are very sorry, but there was an error or errors found with the form you submitted. ";
    echo "These errors appear below.<br /><br />";
    echo $error."<br /><br />";
    echo "Please go back and fix these errors.<br /><br />";
    die();
    }

    // validation expected data exists
    if(!isset($_POST['first_name']) ||
    !isset($_POST['last_name']) ||
    !isset($_POST['email']) ||
    !isset($_POST['telephone']) ||
    !isset($_POST['comments'])) {
    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['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['comments']; // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
    if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
    }
    $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.<br />';
    }
    if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
    }
    if(strlen($comments) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid, Or long enough.<br />';
    }
    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 .= "Telephone: ".clean_string($telephone)."\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);
    ?>

    <!-- include your own success html here -->

    Thank you for contacting us with your story. We will be in touch shortly.
    <?php
    }
    ?>
    Last edited by ralph.m; Sep 12, 2012 at 04:12. Reason: generalised email address

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,117
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    Hey James, could you show us your HTML too?

    Also, what error do you get?
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2012
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The error i get is just the error text in the form no actualy error code:-
    We are very sorry, but there was an error or errors 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.


    HtML :-

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Sell Your Story at Pep Publishing</title>
    <meta name="" content="contact details" />
    <!-- Date: 2012-08-30 -->
    <link rel=StyleSheet href="css/styles.css" TYPE="text/css">
    <style type="text//css"></style>
    </head>

    <body>
    <nav>
    <ul>
    <li><a href="index.html">Home</a></li>
    <li><a href="contact.html" rel="shadowbow">Contact</a>
    <ul>
    <li><a href="#">How To Find us</a></li>
    <li><a href="#">Sell Us A Story</a></li>
    <li><a href="#">Email Us</a></li>
    <li><a href="#">Work For PEP</a></li>
    </ul>
    </li>
    <li><a href="#">Magazines</a>
    <ul>
    <li><a href="www.loveitmagazine.co.uk">LoveIt</a></li>
    <li><a href="www.fullhousemagazine.co.uk">Full House!</a></li>
    </ul>
    </li>
    <li><a href="Advertise.html">Advertise</a></li>
    </ul>
    </nav>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>

    <form name="storyform" method="post" action="send_form_email_story.php">

    <div>
    <h1>Sell Us Your Story/h1>
    <label>
    <span>First Name</span><input id="first_name" type="text" name="name" />
    </label>

    <label>
    <span>Last Name</span><input id="last_name" type="text" name="name" />
    </label>

    <label>
    <span>Email Address</span><input id="email" type="text" name="email" />
    </label>

    <label>
    <span>Telephone</span><input id="telephone" type="text" name="telephone" />
    </label>

    <label>
    <span>Your Story</span>
    <br />
    <textarea id="comments" name="comments"></textarea>

    <input type="submit" value="Submit">
    </label>

    </div>
    </form>



    </body>




    </html>

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,071
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    You need to update the name attributes of your first and last name fields
    HTML Code:
    <label>
    <span>First Name</span><input id="first_name" type="text" name="name" />
    </label>
    
    <label>
    <span>Last Name</span><input id="last_name" type="text" name="name" />
    </label>
    Should be
    HTML Code:
    <label>
    <span>First Name</span><input id="first_name" type="text" name="first_name" />
    </label>
    
    <label>
    <span>Last Name</span><input id="last_name" type="text" name="last_name" />
    </label>
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2012
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks didnt notice that ! something so small !! sometimes just need a 2nd set of eyes thanks a lot guys!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •