Skip navigation
Maxxll12
Currently Being Moderated

Contact From Help! PHP and HTML

Apr 11, 2013 11:41 AM

Hello,

I have a problem that I can't solve myself.

 

When I press the submit button it doesn't sends it to my mail. Instead it shows the .php file in my browser.

I placed contact.php at the same location as the contact.htm

 

It would be really appreciated if someone could help me!

 

This is the HTML (contact.htm):

 

<form action="contact.php" method="post" id="contact_form">

                        <fieldset>                           

                                  <ol>

                                <li>

                                            <label for="name">Name</label><input type="name" name="name" value="" size="77" maxlength="" id="name" />

                                      </li>

                                      <li>

                                      <label for="email">Email Address</label><input type="email" name="email" value="" size="77" maxlength="" id="email" />

                                        </li>

                                <li>

                                      <label for="subject">Subject</label><input type="subject" name="subject" value="" size="77" maxlength="" id="subject" />

                                        </li>

                                        <li>

                                            <label for="message">Description</label><textarea name="message" rows="10" cols="57" id="message"></textarea>

                                        </li>

                                        <li>

                                            <input type="submit" name="submit" value="SUBMIT" size="" maxlength="" />

                                        </li>

                                  </ol>

                        </fieldset>

                    </form>

 

And this is the PHP (contact.php):

 

<?php

 

 

if($_POST['submit']) {

if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['subject']) || empty($_POST['message'])) {

$error = true;

} else {

 

 

$to = "name@domain.com";

 

 

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

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

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

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

 

 

$messages = "Naam: $name \r\n Email: $email \r\n Bericht: $messages";

$headers = "From: . $name";

$mailsent = mail($to, $subject, $messages, $headers);

}

}

 

 

?>


 
Replies
  • Currently Being Moderated
    Apr 11, 2013 12:47 PM   in reply to Maxxll12

    OK, here's the deal. You need to completely check to see that your server handles php scripts. That's on you.

     

    You also need to build good HTML pages  with good forms, but I'll give you the form I use and the php that will make it work:

     

    Here's the form with a little php at the top. Your first page will be your Contact page and it will have the form. This page must have the extension .php and not .html.:

     

    <form method="post" action="send.php">

    <p>

      <!-- DO NOT change ANY of the php sections -->

      <?php

    $ipi = getenv("REMOTE_ADDR");

    $httprefi = getenv ("HTTP_REFERER");

    $httpagenti = getenv ("HTTP_USER_AGENT");

    ?>

     

      <input type="hidden" name="ip" value="<?php echo $ipi ?>" />

      <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />

      <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />

     

     

      Your Name: <br />

      <input type="text" name="visitor" size="35" />

      <br />

      Your Email:<br />

      <input type="text" name="visitormail" size="35" />

      <br />

      Your Phone:<br />

      <input type="text" name="visitorphone" size="35" />

      <br />

      Address<br />

      <input type="text" name="address" size="35" /><br />

      City<br />

      <input type="text" name="city" size="35" /> <br />

      State   Zip<br />

        <input type="text" name="state" size="3" /> <input type="text" name="zip" size="11" /><br />

      Mail Message:<br />

      <textarea name="notes" rows="4" cols="38"></textarea>

      <br />

      <input type="submit" value=" Send Mail " />

      </p>

                  <p>Please fill out the entire form to send a message or you will be instructed to return back to this page until the form is fully filled out.</p>

            </form>    


    Now, it's time to make the part of your little email-sender that does the hard work. Make another page in your website and you must call it "send.php" because that is the action that will be taken Name it something else and nothing works.

     

            <h1>Thank you!</h1>

          <h2>Your message is below</h2>

          <p>If your message was entered correctly, it will show below and someone will get back in touch with you shortly. If it was not, you will be instructed to go back and fill out the form correctly.</p>

        <!-- Reminder: Add the link for the 'next page' (at the bottom) -->

    <!-- Reminder: Change 'YourEmail' to your real email address -->

    <?php

     

     

    $ip = $_POST['ip'];

    $httpref = $_POST['httpref'];

    $httpagent = $_POST['httpagent'];

    $visitor = $_POST['visitor'];

    $visitormail = $_POST['visitormail'];

    $visitorphone = $_POST['visitorphone'];

    $notes = $_POST['notes'];

    $address = $_POST['address'];

    $city = $_POST['city'];

    $state = $_POST['state'];

    $zip = $_POST['zip'];

     

     

     

     

    if (eregi('http:', $notes)) {

    die ("Do NOT try that! ! ");

    }

    if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))

    {

    echo "<h2>Use Back - Enter valid e-mail</h2>\n";

    $badinput = "<h2>Your message was NOT submitted</h2>\n";

    echo $badinput;

    die ("Go back! ! ");

    }

     

    if(empty($visitor) || empty($visitormail) || empty($visitorphone) || empty($notes )) {

    echo "<h2>Use your Back button - fill in all fields, No message was sent.</h2>\n";

    die ("Use back! ! ");

    }

     

    $todayis = date("l, F j, Y, g:i a") ;

     

    $subject = New_Contact;

     

    $notes = stripcslashes($notes);

     

    $message = " $todayis [EST] \n

    Message: $notes \n

    From: $visitor ($visitormail)\n

    Telephone: $visitorphone ($visitorphone)\n

    Address: $address \n

    City: $city \n

    State: $state, Zip: $zip \n

    Additional Info : IP = $ip \n

    ";

     

     

    $from = "From: $visitormail\r\n";

     

    mail("YourEmail", $subject, $message, $from);

     

    ?>

     

    <p>

    Date: <?php echo $todayis ?>

    <br />

    Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )  <?php echo $visitorphone ?>

    <br /><?php echo $address ?> <?php echo $city ?>, <?php echo $state ?> <?php echo $zip ?>

    <br />

    Message:<br />

    <?php $notesout = str_replace("\r", "<br/>", $notes);

    echo $notesout; ?>

    <br />

    Your IP number <?php echo $ip ?> has been recorded for your protection.

     

     

    <br /><br />

        <p>Return to our <a href="index.html">Home</a> page</p>

     
    |
    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