problem with basic contact us form

Discussion in 'PHP' started by GreenBen, Oct 5, 2012.

  1. #1
    Hi all, so I'm having a problem with my PHP form, I'm brand new to PHP so its all a bit confusing. I've copied a standard form from google, but it doesn't quite seem to be working properly.. would anybody mind taking a look?


    Here's the link- http://moretrafficwebsite.co/test.html


    And the code-


    
    <html>
    <head>
    </head>
    <body>
    
    
    <?php 
    if ($_POST["email"]<>'') { 
        $ToEmail = 'admin@moretrafficwebsite.co'; 
        $EmailSubject = 'Traffic Inquiry'; 
        $mailheader = "From: ".$_POST["email"]."\r\n"; 
        $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
        $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
        $MESSAGE_BODY = "Name: ".$_POST["name"].""; 
        $MESSAGE_BODY .= "Email: ".$_POST["email"].""; 
        $MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"]).""; 
        mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 
    ?> 
    Your message was sent
    <?php 
    } else { 
    ?> 
    <form action="test.php" method="post">
    <table width="400" border="0" cellspacing="2" cellpadding="0">
    <tr>
    <td width="29%" class="bodytext">Your name:</td>
    <td width="71%"><input name="name" type="text" id="name" size="32"></td>
    </tr>
    <tr>
    <td class="bodytext">Email address:</td>
    <td><input name="email" type="text" id="email" size="32"></td>
    </tr>
    <tr>
    <td class="bodytext">Comment:</td>
    <td><textarea name="comment" cols="45" rows="6" id="comment" class="bodytext"></textarea></td>
    </tr>
    <tr>
    <td class="bodytext"> </td>
    <td align="left" valign="top"><input type="submit" name="Submit" value="Send"></td>
    </tr>
    </table>
    </form> 
    <?php 
    }; 
    ?>
    
    
    
    
    </body>
    </html>
    
    Code (markup):
    Thanks, Ben.
     
    Solved! View solution.
    GreenBen, Oct 5, 2012 IP
  2. benjaminp

    benjaminp Guest

    Messages:
    1,212
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    230
    #2
    Haven't looked through the code, but for starters you need to change the file extension from .html to .php.
     
    benjaminp, Oct 5, 2012 IP
  3. GreenBen

    GreenBen Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the reply.

    The link i provided had the problem page contained within it. Here is the PHP page alone - moretrafficwebsite.co/content/contact_us.php
     
    GreenBen, Oct 5, 2012 IP
  4. #4
    Form data is being sent to test.php, which in your case does not exist.
    Please change it so that it would match the file name you are running this form from.
     
    Web Solutions, Oct 6, 2012 IP
  5. muslim_ansari

    muslim_ansari Active Member

    Messages:
    33
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    53
    #5
    simply change file extension from .HTML to .php
     
    muslim_ansari, Oct 6, 2012 IP
  6. alfa_375

    alfa_375 Active Member

    Messages:
    445
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #6
    Yes! Just change the extension from test.html to test.php. Then also let us know where you are running the code. I mean with localhost server or on your website or where? this is important, the php code will not execute like html file.
     
    alfa_375, Oct 6, 2012 IP
  7. GreenBen

    GreenBen Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I was sending the form the test.php instead of contact_us.php d'oh! Thanks guys, saved me a lot of head wreck time there :)
     
    GreenBen, Oct 6, 2012 IP
  8. Drent123

    Drent123 Peon

    Messages:
    105
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Basic contact us form design in html.
     
    Drent123, Oct 10, 2012 IP