How can I create a Contact form without PHP?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lucian Haralamb
    New Member
    • Feb 2011
    • 1

    How can I create a Contact form without PHP?

    I want to create a Contact page on my website with the following form boxes:
    ----------------
    Name
    e-mail address
    Comments

    Submit (button)
    ----------------
    I want the customers to send me the comments via email but without prompting for the the local mail client ("mailto:"). Is there a way to write all this in html/css? without applying php? The submit button will send the message right from the browser.

    If not, can you help me with the php engine? maybe some advice on how to embed the php code to my ordinary html/css site.

    Thank you very much in advance :)
  • drhowarddrfine
    Recognized Expert Expert
    • Sep 2006
    • 7434

    #2
    I don't even know PHP. PHP does nothing but set up the HTML for the form using form and input elements. Do you know enough HTML to do that?

    Comment

    • Markus Igeland
      New Member
      • Feb 2011
      • 14

      #3
      As far as I know this is not possible. But, if you use this HTML and PHP, it'll be possible:

      Your HTML-file (contact.html)
      Code:
      <form action="mail.php" method="post">
      Name: <input type="text" name="name"><br>
      E-mai: <input type="text" name="email"><br>
      Comment: <br>
      <textarea name="comment" cols=50 rows=10></textarea>
      </form>
      Your PHP-file (mail.php):
      Code:
      <?php
      function isEmail($email){
      if(preg_match("/^(\w+((-\w+)|(\w.\w+))*)\@(\w+((\.|-)\w+)*\.\w+$)/",$email)){
      return true;
      }
      else {
      return false;
      }
      }
      
      if( isEmail($_POST['email']) ) {
      $name = $_POST['name'];
      $email = $_POST['email'];
      $comment = $_POST['comment'] . "\r\n\r\n-- \r\n$name";
      $datetime = date("Y-m-d H:i:s");
      $your_email = 'FILL IN YOUR EMAIL';
      $subject = 'Comment from HTML-form: ' . substr($comment, 0, 15) . '...';
      }
      if( mail ($your_email, $subject, $comment, "From: $email")){
      header("Location: contact.html"); //Here, you can replace contact.html with another page that will say "Thank you for your feedback or something like that.
      }
      else {
      echo "Something messed up! I'm sorry! =( <br> Here are the data you sent to this page. Send it to me in an email at $your_email, and I'll answer you. =)<br><br>Name: $name<br>E-mail: $email<br>Comment:<br>$comment";
      }
      ?>
      Tell me if the code [edit]doesn't work[/edit], mate.
      Last edited by acoder; Feb 17 '11, 01:49 PM. Reason: Cleaned up foul language in post

      Comment

      • drhowarddrfine
        Recognized Expert Expert
        • Sep 2006
        • 7434

        #4
        The only part that needs PHP is handling it on the server side. No language is needed to collect and send the data.

        Comment

        • Markus Igeland
          New Member
          • Feb 2011
          • 14

          #5
          @drhowarddrfine
          Was that post directed to me, or to OP?

          Comment

          • JKing
            Recognized Expert Top Contributor
            • Jun 2007
            • 1206

            #6
            I would suggest at the very least validating the email address. Otherwise a user could throw in several email addresses and use your form to spam people.

            Comment

            • Markus Igeland
              New Member
              • Feb 2011
              • 14

              #7
              JKing: That's true. I should have included it, but I forgot.

              I'll edit my post and add a function to check that the email is valid. [done]

              Comment

              Working...