Skip navigation
Currently Being Moderated

Still struggling with contact form

Mar 4, 2013 6:05 AM

Hey DWers-

 

I added osgood's form (thanks for posting that) from another thread. The form displays on the page, but doesn't work and I'm sure that's because I've macerated the code along the way. 

 

I think it's clashing with the existing <html> tags, but I'm not sure what I can/can't take out of the existing code as it's a bit more complicated than I'm used to. It's a responsive design so I don't want to fix one thing (the email form) and destroy another (the responsiveness).  I'm ready to slap a Facebook link on the page and say see ya!

 

Anyway if anyone has some time, the link is http://www.dirtbikes101.com/contactform.php

 

 

Thank you, thank you, and thank you again!

 

 

ps - the error message is

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@dirtbikes101.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.


 

Apache/2.2.3 (CentOS) Server at www.dirtbikes101.com Port 80

 
Replies
  • Sudarshan Thiagarajan
    4,000 posts
    Oct 15, 2010
    Currently Being Moderated
    Mar 4, 2013 6:12 AM   in reply to lostinny

    We need to see your PHP code. Can you copy & paste the code from 'contactform.php' file? We cannot see the actual PHP code on our web browser with the link you've given - since it is a server side script.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 4, 2013 7:38 AM   in reply to lostinny

    Yup, can you post the php here. The form is working up until the point it needs to send the mail so you have probably configured something incorrectly.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 4, 2013 9:03 AM   in reply to lostinny

    There are two possible reasons that you are getting the  'Internal Server Error'

     

    Most likely it's associated with the 'header'  line at the end of the php code block:

     

    header("Location: http://hybrid.concordia.ca/~mstrpln/thankyou.html");        //Redirect page -- change to your own page

     

     

    The line must come before any other code is output to the page. Can I suggest you move the whole block of php code which processes the form information to the start of the page before your doctype declaration:

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

     

     

    Then go through the php code and get rid of any white space between the lines of php code if there is any because the 'header' also doesn't like that either.

     

    Other that that I can't see any reason for the error. I took your code and tested it on my server and it worked. It didn't redirect to the 'thank you page' though until I moved the whole block of code above the doctype. However it did send the information from the form without the necessity to do this. Servers work slightly differently to each other so hopefully if you move the block of php code and delete and white space between the lines of php code, as suggested above, it should work,

     
    |
    Mark as:
  • Sudarshan Thiagarajan
    4,000 posts
    Oct 15, 2010
    Currently Being Moderated
    Mar 4, 2013 9:05 AM   in reply to lostinny

    Your page is illegally constructed. Contains 2 Doctype declarations and 2 body tags.

     

    Move the PHP block all the way to the top of your page. Replace your current code with this:

     

    <?php

     

    if (array_key_exists('submit', $_POST)) {

     

    // check name field

     

    $name = trim($_POST['name']);

     

    if (empty($name)) {

     

    $error['name'] = 'Please enter your name';

     

    }

     

    elseif ($name == 'Please enter your name') {

     

    $error['name'] = '';

     

    }

     

    // check email field

     

    $email = trim($_POST['email']);

     

    if (empty($email)) {

     

    $error['email'] = 'Please enter your email address';

     

    }

     

    elseif ($email == 'Please enter your email address') {

     

    $error['email'] = '';

     

    }

     

    // check comment field

     

    $comment = trim($_POST['comment']);

     

    if (empty($comment)) {

     

    $error['comment'] = 'Please enter your comment';

     

    }

     

    elseif ($comment == 'Please enter your comment') {

     

    $error['comment'] = '';

     

    }

     

    if (!empty($_POST['ufo'])) { return false; }

     

    // recipient

     

    $to = "thegrinfactor@gmail.com";

     

    // email subject

     

    $subject = "from MSTRPLN website form";

     

    // sender

     

    $sender = "From: ".$_POST['email']."\r\n";

     

    // build message

     

    $message = "Name: $name\n\n";

     

    $message .= "Email Address: $email\n\n";

     

    $message .= "Comment: $comment\n\n";

     

    // send email if no form erorrs

     

    if (!isset($error)) {

     

    mail($to, $subject, $message, $sender);

     

    mail($reply, $replysubject, $replymessage, $replyfrom);

     

    header("Location: http://hybrid.concordia.ca/~mstrpln/thankyou.html");        //Redirect page -- change to your own page

     

    }

     

    }

     

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <meta name="viewport" content="width=device-width" />

    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />

    <title>Dirt Bikes 101 Contact page - give us a shout!</title>

    <script type="text/javascript" src="p7adaptations/p7EHCscripts.js"></script>

    <link href="p7adaptations/p7adapt-03.css" rel="stylesheet" type="text/css" />

    <link href="p7adaptations/p7adapt-03-response.css" rel="stylesheet" type="text/css" />

    <link href="http://fonts.googleapis.com/css?family=Federo" rel="stylesheet" type="text/css">

    <style type="text/css">

    body, td, th {

        font-size: 0.85em;

    }

     

    body {

        background-image: url(../images/brownbglarge.jpg);

    }

    </style>

    <link rel="shortcut icon"

               href="../images/favicon.ico">

    </head>

     

    <body>

    <script type="text/javascript">//EMPTY SCRIPT TO FIX IPHONE-IPOD RENDERING BUGS</script>

    <div id="masthead">

      <h1><a href="index.html"><img src="../images/headerP7.jpg" width="720" height="90" border="0" class="scaled" /></a></h1>

    </div>

    <div id="columns">

      <div class="navigation">

        <div class="content">

          <ul class="menu-bar">

            <li><a href="index.html"> Home</a></li>

            <li><a href="about.html">About</a></li>

            <li><a href="gearbag.html">Gear Bag</a></li>

            <li><a href="resources.html">Links</a></li>

            <li><a href="contactform.php">Contact</a></li>

            <li><a href="privacy.html">Privacy Policy </a></li>

          </ul>

        </div>

      </div>

      <div class="main-content">

        <div class="content p7ehc-1">

          <h2 class="header"> </h2>

          <h2 class="header">Contact Us</h2>

          <p>Sorry for making you use a form, but the spam bots made this a necessity.  Thanks.</p>

          <p> </p>

        

          <form method="post" id="contactform" action="contactform.php">

            <p>

              <label for="name">Name</label>

            </p>

            <input type="text" id="name" name="name" tabindex="1" <?php if(isset($error['name'])) echo "style='border: 1px solid #C00; color: #C00;'"; ?> value="<?php if(isset($name)) {echo $name;} ?><?php if(isset($error['name'])) echo $error['name']; ?>" onfocus="this.value=''"/>

            <p>

              <label for="email">Email</label>

            </p>

            <input type="text" id="email" name="email" tabindex="2" <?php if(isset($error['email'])) echo "style='border: 1px solid #C00; color: #C00;'"; ?> value="<?php if(isset($email)) {echo $email;} ?><?php if(isset($error['email'])) echo $error['email']; ?>" onfocus="this.value=''"/>

            <p>

              <label for="comment">Your Message</label>

            </p>

            <p>

              <textarea name="comment" id="comment" tabindex="4" <?php if(isset($error['comment'])) echo "style='border: 1px solid #C00; color: #C00;'"; ?>><?php if(isset($comment)) {echo $comment;} ?><?php if(isset($error['comment'])) echo $error['comment']; ?>

            </textarea>

              <input name="submit" type="submit" id="submit" tabindex="5" value="Send Message" />

              <input type="text" name="ufo" style="visibility: hidden;">

            </p>

            <p> </p>

          </form>

        </div>

      </div>

      <div class="sidebar">

        <div class="content p7ehc-1">

          <h2 class="header"> </h2>

          <h2 class="header"> </h2>

          <p class="header"><a href="http://online2.msf-usa.org/msf/Default.aspx"><img src="../images/msflogo.jpg" alt="msf logo" width="100" height="44" border="0" class="scaled-max" /></a></p>

          <p><a href="http://www.americanmotorcyclist.com/"><img src="../images/amalogo.jpg" alt="ama logo" width="100" height="46" border="0" class="scaled-max" /></a></p>

          <p><a href="http://www.dirtbikeschool.org/"><img src="../images/msfdblogo.jpg" alt="msf dirt bike school logo" width="100" height="44" border="0" class="scaled-max" /></a></p>

          <p><a href="http://www.nohvcc.org/"><img src="../images/NOHVCClogo.gif" alt="nohvcc logo" width="100" height="45" border="0" class="scaled-max" /></a></p>

          <p><a href="http://treadlightly.org/"><img src="../images/tredlitlylogo.gif" alt="tread lighlty logo" width="100" height="41" border="0" class="scaled-max" /></a></p>

          <p><a href="http://www.smf.org/"><img src="../images/snellbutton.jpg" alt="snell foundation logo" width="100" height="46" border="0" class="scaled-max" /></a></p>

        </div>

      </div>

      <span class="clearfix"> </span> </div>

    <div id="footer">&copy;2011-2013 Dirt Bikes 101.com</div>

    </body>

    </html>

    It should work.

     
    |
    Mark as:
  • Sudarshan Thiagarajan
    4,000 posts
    Oct 15, 2010
    Currently Being Moderated
    Mar 4, 2013 9:06 AM   in reply to osgood_

    @osgood, just noticed your reply too. We were replying at the same time, I guess!

     

    The OP's code also had an illegal construct. 2 doctype declarations. Hence, I posted the revised code.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 4, 2013 9:09 AM   in reply to lostinny

    The form page contains NO <head> region! Now, that won't make much difference, but it means your page will not have a title, and it will not validate.

     

    Then try removing this line from your processing page -

     

    mail($reply, $replysubject, $replymessage, $replyfrom);

     

    It is likely what is throwing the error.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 4, 2013 9:11 AM   in reply to MurraySummers

    MurraySummers wrote:

     

    The form page contains NO <head> region! Now, that won't make much difference, but it means your page will not have a title, and it will not validate.

     

    Then try removing this line from your processing page -

     

    mail($reply, $replysubject, $replymessage, $replyfrom);

     

    It is likely what is throwing the error.

     

    Well spotted Murray.......that shouldn't be there it's part of the auto responder bit, which was removed for simplicity sake.  Didn't make much difference on my server but other servers may react differently.

     
    |
    Mark as:
  • Sudarshan Thiagarajan
    4,000 posts
    Oct 15, 2010
    Currently Being Moderated
    Mar 4, 2013 9:13 AM   in reply to MurraySummers

    Murray, the OP's code has 2 blocks within it. Or, is it just me noticing it?! Because neither did osgood post about that, nor did you! Please tell me it is not just me - or that would possibly mean that I'm going to have to take a 15-day vacation to clear my head

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 4, 2013 9:13 AM   in reply to Sudarshan Thiagarajan

    Sudarshan Thiagarajan wrote:

     

    @osgood, just noticed your reply too. We were replying at the same time, I guess!

     

    The OP's code also had an illegal construct. 2 doctype declarations. Hence, I posted the revised code.

     

    I didn't see that, well spotted.

     
    |
    Mark as:
  • Jim Carpenter
    546 posts
    Apr 6, 2006
    Currently Being Moderated
    Mar 4, 2013 9:24 AM   in reply to Sudarshan Thiagarajan

    Murray, go ahead and take the 15 days, it's always good!

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 4, 2013 9:31 AM   in reply to Sudarshan Thiagarajan

    Heh - I read the post as being two different pages. But I believe you were right. No wonder the server is puking....

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 4, 2013 9:32 AM   in reply to Jim Carpenter

    See you in two weeks (give or take)!

     
    |
    Mark as:
  • Sudarshan Thiagarajan
    4,000 posts
    Oct 15, 2010
    Currently Being Moderated
    Mar 4, 2013 9:40 AM   in reply to MurraySummers

    Thank heavens. Murra & osgood, you guys saved me a couple of grand + 2 weeks of loss-of-income

     
    |
    Mark as:
  • Sudarshan Thiagarajan
    4,000 posts
    Oct 15, 2010
    Currently Being Moderated
    Mar 4, 2013 11:15 AM   in reply to lostinny

    Well, one more thing I'd like to point out here.

     

    Check with your host if your server supports php_sendmail function as that is what this code uses.

     

    If they say they dont, ask them if the server supports sendmail with smtp_auth (authorizing each form-send action using an e-mail id and its password to route it through a server properly). If they say they will support that, your code may have to be re-written a bit.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 4, 2013 11:27 PM   in reply to lostinny

    lostinny wrote:

     

    osgood - am glad to know it worked for you but can I simply delete the "header" info?  I don't care if they get a thank you at this point. I just want them to be able to send me an email.

     

     

    Yes,

     

    You can delete the 'header' line:

     

    header("Location: http://hybrid.concordia.ca/~mstrpln/thankyou.html");        //Redirect page -- change to your own page

     

     

    Also as Murray pointed out you don't really need this line either:

     

    mail($reply, $replysubject, $replymessage, $replyfrom);

     

     

    Apart from that I don't know what the issue could be. It's never failed on any of the servers I've used it on.

     

    As I say the form is working up until the point it needs to send the information to your server. The validation part is working fine, it's only after that when it breaks down for you, so that really points to a server issue.

     

    At this point I would suggest testing it on a different server if you have another site hosted on one. This will provide more clues as to what the problem might be.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points