www.webdeveloper.com
Results 1 to 7 of 7

Thread: Problem with contact form : Internal server error

  1. #1
    Join Date
    Dec 2012
    Posts
    5

    Problem with contact form : Internal server error

    Hi,

    I have created a contact form in html and .php. When I click on the submit button it is giving me an error "Internal server error"

    check out my website www.yourgoal.co.in for contact form at the end of each page.

    Code that I used to create the form (HTML & PHP) is

    HTML code

    <section class="one_quarter lastbox">
    <h2 class="title">Contact Us</h2>
    <form method="post" action="contact.php">
    <fieldset>
    <legend>Contact Form:</legend>
    <label for="cf_name">Name:</label>
    <input type="text" name="cf_name" id="cf_name" value="" style="background-color:#FFF">
    <label for="cf_email">Email:</label>
    <input type="text" name="cf_email" id="cf_email" value="" style="background-color:#FFF">
    <label for="cf_subject">Subject:</label>
    <input type="text" name="cf_subject" id="cf_subject" value="" style="background-color:#FFF">
    <label for="cf_message">Message:</label>
    <textarea name="cf_message" id="cf_message" cols="45" rows="10" style="background-color:#FFF"></textarea>
    <button type="submit" value="send">Submit</button>
    </fieldset>
    </form>
    </section>

    PHP code is below

    <?

    $your_email = "admin@yourgoal.co.in";

    $headers= "From: ".$_POST['name']." <".$_POST['email'].">\r\n";
    $headers.='Content-type: text/html; charset=utf-8';
    mail($your_email, $_POST['subject'], "
    <html>
    <head>
    <title>Contact Message</title>
    </head>
    <body>
    Contact Message<br><br>
    Name : ".$_POST['name']."<br>
    Email : ".$_POST['email']."<br>
    <?php /*?>Telephone : ".$_POST['telephone']."<br><br><?php */?>
    Subject : ".$_POST['subject']."<br>
    Message : <br>".$_POST['message']."<br>
    </body>
    </html>" , $headers);
    header("Location: ./index.htm?page=Services.htm");
    ?>

  2. #2
    Join Date
    Sep 2008
    Location
    Akron, OH
    Posts
    1,112
    Start your php like this:

    Code:
    <?php
    You're missing the PHP piece.
    I'm always up for networking with fellow web professionals. Connect with me on LinkedIn if you like!

  3. #3
    Join Date
    Mar 2009
    Posts
    452
    PHP Code:
    <?php
    $your_email 
    "admin@yourgoal.co.in";

    $headers"From: ".$_POST['name']." <".$_POST['email'].">\r\n";
    $headers.='Content-type: text/html; charset=utf-8';
    mail($your_email$_POST['subject'], "
    <html>
    <head>
    <title>Contact Message</title>
    </head>
    <body>
    Contact Message<br><br>
    Name : "
    .$_POST['name']."<br>
    Email : "
    .$_POST['email']."<br>
    Subject : "
    .$_POST['subject']."<br>
    Message : <br>"
    .$_POST['message']."<br>
    </body>
    </html>" 
    $headers);
    header("Location: ./index.htm?page=Services.htm");
    ?>
    Last edited by ZABI; 01-07-2013 at 02:28 PM.

  4. #4
    Join Date
    Jul 2007
    Location
    Wisconsin
    Posts
    468
    Your mail() command is screwed up, because of the formatting. You're already "inside" PHP code, so you cant wrap your PHP comment in php tags, but rather you need to concatenate the string properly.

    Review and try this PHP code, instead:

    PHP Code:
        <?php
        $your_email 
    "admin@yourgoal.co.in";

        
    $tmpMessage "<html>
    <head>
    <title>Contact Message</title>
    </head>"
    ;
        
    $tmpMessage .= "<body>
    Contact Message<br><br>
    Name : "
    .$_POST['name']."<br>
    Email : "
    .$_POST['email']."<br>" 
    /* Telephone : ".$_POST['telephone'] */."<br><br>
    Subject : "
    .$_POST['subject']."<br>
    Message :<br>"
    .
    $_POST['message']."<br>
    </body>
    </html>"
    ;

        
    $headers"From: ".$_POST['name']." <".$_POST['email'].">\r\n";
        
    $headers.='Content-type: text/html; charset=utf-8';
        
    mail($your_email$_POST['subject'], $tmpMessage $headers);
        
    header("Location: ./index.htm?page=Services.htm");
        
    ?>

  5. #5
    Join Date
    Dec 2012
    Posts
    5
    Hi,

    Tried out as suggested but of no use.....

    Any other suggestions??

  6. #6
    Join Date
    Aug 2011
    Posts
    12
    Quote Originally Posted by cbVision View Post
    Start your php like this:

    Code:
    <?php
    You're missing the PHP piece.
    actually this should not cause an internal server error because <? is just a short way of writing <?php which <? is called short tags not all host have short tags turned on but if its off it would just show the page as plain text it would not attempt to process the php code

  7. #7
    Join Date
    Aug 2011
    Posts
    12
    Quote Originally Posted by OctoberWind View Post
    Your mail() command is screwed up, because of the formatting. You're already "inside" PHP code, so you cant wrap your PHP comment in php tags, but rather you need to concatenate the string properly.

    Review and try this PHP code, instead:

    PHP Code:
        <?php
        $your_email 
    "admin@yourgoal.co.in";

        
    $tmpMessage "<html>
    <head>
    <title>Contact Message</title>
    </head>"
    ;
        
    $tmpMessage .= "<body>
    Contact Message<br><br>
    Name : "
    .$_POST['name']."<br>
    Email : "
    .$_POST['email']."<br>" 
    /* Telephone : ".$_POST['telephone'] */."<br><br>
    Subject : "
    .$_POST['subject']."<br>
    Message :<br>"
    .
    $_POST['message']."<br>
    </body>
    </html>"
    ;

        
    $headers"From: ".$_POST['name']." <".$_POST['email'].">\r\n";
        
    $headers.='Content-type: text/html; charset=utf-8';
        
    mail($your_email$_POST['subject'], $tmpMessage $headers);
        
    header("Location: ./index.htm?page=Services.htm");
        
    ?>
    even ur code is incorrect should be this

    PHP Code:
    <?php
        $your_email 
    "admin@yourgoal.co.in";

        
    $tmpMessage "<html>
    <head>
    <title>Contact Message</title>
    </head>"
    ;
        
    $tmpMessage .= "<body>
    Contact Message<br><br>
    Name : "
    .$_POST['name']."<br>
    Email : "
    .$_POST['email']."<br> 
    Telephone : "
    .$_POST['telephone']."<br>
    Subject : "
    .$_POST['subject']."<br>
    Message :<br>"
    .
    $_POST['message']."<br>
    </body>
    </html>"
    ;

        
    $headers"From: ".$_POST['name']." <".$_POST['email'].">\r\n";
        
    $headers.='Content-type: text/html; charset=utf-8';
        
    mail($your_email$_POST['subject'], $tmpMessage $headers);
        
    header("Location: ./index.htm?page=Services.htm");
        
    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles