Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: php contact form error

  1. #1
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default php contact form error

    hello

    I'm a new beginner in php programing and need essential help

    i have a contact form which have to send data to specific email and redirect to than you page but when submitting it displays the php code in IE page and never redirect to thank you page , please help me and correct for me

    below is the code:

    <html>
    <head>
    <title>Contact us</title>
    <!-- define some style elements-->
    <style>
    h1
    {
    font-family : Arial, Helvetica, sans-serif;
    font-size : 16px;
    font-weight : bold;
    }
    label,a
    {
    font-family : Arial, Helvetica, sans-serif;
    font-size : 12px;
    }

    </style>
    <!-- a helper script for vaidating the form-->
    <script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>
    </head>
    </head>

    <body>
    <h1>Contact us</h1>
    <form method="POST" name="contactform" action="contact-form-handler.php">
    <p>
    <label for='name'>Your Name:</label> <br>
    <input type="text" name="name">
    </p>
    <p>
    <label for='email'>Email Address:</label> <br>
    <input type="text" name="email"> <br>
    </p>
    <p>
    <label for='message'>Message:</label> <br>
    <textarea name="message"></textarea>
    </p>
    <input type="submit" value="Submit"><br>
    </form>
    ______________________

    <script language="JavaScript">
    // Code for validating the form
    var frmvalidator = new Validator("contactform");
    frmvalidator.addValidation("name","req","Please provide your name");
    frmvalidator.addValidation("email","req","Please provide your email");
    frmvalidator.addValidation("email","email","Please enter a valid email address");
    </script>
    _______________________________________

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Your host supports PHP, correct? If so please provide the code of 'contact-form-handler.php'
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Jul 2011
    Location
    Lockport, Illinois
    Posts
    35
    Thanks
    4
    Thanked 2 Times in 2 Posts

    Default

    Could you please give us the code to contact-form-handler.php? It doesnt look like anything is wrong with your code there on a quick glance, so your error may be in contact-form-handler.php

  4. #4
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hi this is mycontact- form-handler.php code

    <?php
    $errors = '';
    $myemail = 'yourname@website.com';//<-----Put Your email address here.
    if(empty($_POST['name']) ||
    empty($_POST['email']) ||
    empty($_POST['message']))
    {
    $errors .= "\n Error: all fields are required";
    }

    $name = $_POST['name'];
    $email_address = $_POST['email'];
    $message = $_POST['message'];

    if (!preg_match(
    "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
    $email_address))
    {
    $errors .= "\n Error: Invalid email address";
    }

    if( empty($errors))
    {
    $to = $myemail;
    $email_subject = "Contact form submission: $name";
    $email_body = "You have received a new message. ".
    " Here are the details:\n Name: $name \n Email: $email_address \n Message \n $message";

    $headers = "From: $myemail\n";
    $headers .= "Reply-To: $email_address";

    mail($to,$email_subject,$email_body,$headers);
    //redirect to the 'thank you' page
    header('Location: contact-form-thank-you.html');
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Contact form handler</title>
    </head>

    <body>
    <!-- This page is displayed only if there is some error -->
    <?php
    echo nl2br($errors);
    ?>


    </body>
    </html>

    __________________

  5. #5
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    this is my HTML Form code:

    <html>
    <head>
    <title>Contact us</title>
    <!-- define some style elements-->
    <style>
    h1
    {
    font-family : Arial, Helvetica, sans-serif;
    font-size : 16px;
    font-weight : bold;
    }
    label,a
    {
    font-family : Arial, Helvetica, sans-serif;
    font-size : 12px;
    }

    </style>
    <!-- a helper script for vaidating the form-->
    <script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>
    </head>
    </head>

    <body>
    <h1>Contact us</h1>
    <form method="POST" name="contactform" action="contact-form-handler.php">
    <p>
    <label for='name'>Your Name:</label> <br>
    <input type="text" name="name">
    </p>
    <p>
    <label for='email'>Email Address:</label> <br>
    <input type="text" name="email"> <br>
    </p>
    <p>
    <label for='message'>Message:</label> <br>
    <textarea name="message"></textarea>
    </p>
    <input type="submit" value="Submit"><br>
    </form>

    <script language="JavaScript">
    // Code for validating the form
    // Visit http://www.javascript-coder.com/html...lidation.phtml
    // for details
    var frmvalidator = new Validator("contactform");
    frmvalidator.addValidation("name","req","Please provide your name");
    frmvalidator.addValidation("email","req","Please provide your email");
    frmvalidator.addValidation("email","email","Please enter a valid email address");
    </script>
    <!--


    </body>
    </html>

    _____________________________

  6. #6
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Is there an error message? Do you have other PHP pages that function?
    Corrections to my coding/thoughts welcome.

  7. #7
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    noo threre is more any error messages

  8. #8
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Do you have other PHP pages that function? If it's outputting all the PHP code it is a server error, or PHP is not set up.
    Corrections to my coding/thoughts welcome.

  9. #9
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i reinstalled php on my computer again and put all contact-form-handler.php and contact-form and thank you page in (www folder) and
    //redirect to the 'thank you' page

    edit redirect page to
    header('Location: c:/AppServ/www/contact-form-thank-you.html');

    and when my form on localhost it never geos to thank you page but gives me this messages:


    Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\AppServ\www\contact-form-handler.php on line 32

    Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\contact-form-handler.php:32) in C:\AppServ\www\contact-form-handler.php on line 34

  10. #10
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    So SMTP isn't set up on your local computer, or isn't configured with your PHP that is the first error. The second error is because of the first error, nothing can be outputted before the header is called and that error message is being outputted. You could reverse the order of that and you won't see the error message but once you bring it to a server with SMTP set it still won't send because the header will redirect before it gets there.
    Corrections to my coding/thoughts welcome.

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
  •