Results 1 to 3 of 3

Thread: Please Help Me With This Email Form

  1. #1
    Farrhad A's Avatar
    Farrhad A is offline Netbuilder
    Join Date
    May 2009
    Posts
    846
    Thanks
    38
    Thanked 18 Times in 17 Posts

    Please Help Me With This Email Form

    Hi,

    Please go to Untitled Document and click the contact tab.

    There is a form over there, how do i make it like a working contact form?

    Please can someone help me out.

    Thanks!
    My Blog- Let's Get Talking!
    Are you on Twitter? Let's become friends!

  2. #2
    Zash's Avatar
    Zash is offline WiredStorm.com - Lightning Fast Web Hosting
    Join Date
    Feb 2009
    Location
    New York, USA
    Posts
    1,137
    Blog Entries
    1
    Thanks
    64
    Thanked 121 Times in 93 Posts
    It's actually very simple, I just learned how

    Let's take a look at your HTML form:
    HTML Code:
    <form action="send.php" method="post">
    <img src="http://www.netbuilders.org/images/leave-a.gif" alt="Leave a message">
    <ul>
    <li><input class="text-name" name="contact_name" type="text"></li>
    <li><input class="text-email" name="contact_email" type="text"></li>
    <li><textarea class="message" rows="2" cols="25" name="the_message"></textarea></li>
    <li><input src="http://www.netbuilders.org/images/send.gif" class="submit" alt="submit" type="image"></li></ul></form>
    The important parts are the action="send.php" and the name="X" for the fields.

    Now, let's look at send.php that I just whipped up:

    PHP Code:
    <?php
    // Your Email Here
    $to "youremail@yourdomain.com";

    // The 'From' Email
    $from "from@yourdomain.com";

    // Subject of Email
    $subject "New Contact Form Response";

    $name $_POST['contact_name'];
    $email $_POST['contact_email'];
    $message $_POST['the_message'];  

    $name_new filter_var($nameFILTER_SANITIZE_STRING);  
    $email_new filter_var($emailFILTER_SANITIZE_STRING);
    $message_new filter_var($messageFILTER_SANITIZE_STRING);  

    $headers "From: $from";
    $body "##################################################\nTHIS IS AN AUTOMATED EMAIL - DO NOT RESPOND\n##################################################\n\nSomebody just sent you a message using your contact form.\n\nName: $name_new\nEmail: $email_new\nMessage:\n$message_new\n\n";
    mail($to$subject$body,$headers);
    ?>
    Normal HTML here
    And we'll break it down.

    PHP Code:
    <?php
    // Your Email Here
    $to "youremail@yourdomain.com";

    // The 'From' Email
    $from "from@yourdomain.com";

    // Subject of Email
    $subject "New Contact Form Response";
    This is simply setting variables so you don't have to edit the mess.

    PHP Code:
    $name $_POST['contact_name'];
    $email $_POST['contact_email'];
    $message $_POST['the_message']; 
    These are more variables, and they call upon the form. Where it says $_POST['contact_name'] you would put the name of your field, in this case being contact_name. You would do the same with the rest.

    PHP Code:
    $name_new filter_var($nameFILTER_SANITIZE_STRING);  
    $email_new filter_var($emailFILTER_SANITIZE_STRING);
    $message_new filter_var($messageFILTER_SANITIZE_STRING); 
    This replaces the old variables, sanitizes them (removes any HTML markup), and puts them into new variables.

    PHP Code:
    $headers "From: $from";
    $body "##################################################\nTHIS IS AN AUTOMATED EMAIL - DO NOT RESPOND\n##################################################\n\nSomebody just sent you a message using your contact form.\n\nName: $name_new\nEmail: $email_new\nMessage:\n$message_new\n\n"
    This is the actual email. $headers is going to be the From section, leave it as it is. The $body is what appears in the email. \n is a break. The variables are in it as well (notice we are using the sanitized ones). This is what the email would look like:
    ##################################################
    THIS IS AN AUTOMATED EMAIL - DO NOT RESPOND
    ##################################################

    Somebody just sent you a message using your contact form.

    Name: $name_new
    Email: $email_new
    Message:
    $message_new
    PHP Code:
    mail($to$subject$body,$headers);
    ?>
    Normal HTML here 
    This is the final function that actually sends out the email. Now, you can put normal HTML after this, and that would be your 'Email sent!' page.

    This is a simple form, without validation or anti-spam. Just look up a Google search for that.
    WiredStorm Hosting Solutions
    █ Lightning Fast Shared and Reseller Hosting
    █ cPanel with Softaculous and 24/7 Email (Ticket) Support
    Biodegradable Sunscreen - Unblock Facebook

  3. Thanked by:

    Farrhad A (14 August, 2009)

  4. #3
    Farrhad A's Avatar
    Farrhad A is offline Netbuilder
    Join Date
    May 2009
    Posts
    846
    Thanks
    38
    Thanked 18 Times in 17 Posts
    Quote Originally Posted by Zash View Post
    It's actually very simple, I just learned how

    Let's take a look at your HTML form:
    HTML Code:
    <form action="send.php" method="post">
    <img src="http://www.netbuilders.org/images/leave-a.gif" alt="Leave a message">
    <ul>
    <li><input class="text-name" name="contact_name" type="text"></li>
    <li><input class="text-email" name="contact_email" type="text"></li>
    <li><textarea class="message" rows="2" cols="25" name="the_message"></textarea></li>
    <li><input src="http://www.netbuilders.org/images/send.gif" class="submit" alt="submit" type="image"></li></ul></form>
    The important parts are the action="send.php" and the name="X" for the fields.

    Now, let's look at send.php that I just whipped up:

    PHP Code:
    <?php
    // Your Email Here
    $to "youremail@yourdomain.com";

    // The 'From' Email
    $from "from@yourdomain.com";

    // Subject of Email
    $subject "New Contact Form Response";

    $name $_POST['contact_name'];
    $email $_POST['contact_email'];
    $message $_POST['the_message'];  

    $name_new filter_var($nameFILTER_SANITIZE_STRING);  
    $email_new filter_var($emailFILTER_SANITIZE_STRING);
    $message_new filter_var($messageFILTER_SANITIZE_STRING);  

    $headers "From: $from";
    $body "##################################################\nTHIS IS AN AUTOMATED EMAIL - DO NOT RESPOND\n##################################################\n\nSomebody just sent you a message using your contact form.\n\nName: $name_new\nEmail: $email_new\nMessage:\n$message_new\n\n";
    mail($to$subject$body,$headers);
    ?>
    Normal HTML here
    And we'll break it down.

    PHP Code:
    <?php
    // Your Email Here
    $to "youremail@yourdomain.com";

    // The 'From' Email
    $from "from@yourdomain.com";

    // Subject of Email
    $subject "New Contact Form Response";
    This is simply setting variables so you don't have to edit the mess.

    PHP Code:
    $name $_POST['contact_name'];
    $email $_POST['contact_email'];
    $message $_POST['the_message']; 
    These are more variables, and they call upon the form. Where it says $_POST['contact_name'] you would put the name of your field, in this case being contact_name. You would do the same with the rest.

    PHP Code:
    $name_new filter_var($nameFILTER_SANITIZE_STRING);  
    $email_new filter_var($emailFILTER_SANITIZE_STRING);
    $message_new filter_var($messageFILTER_SANITIZE_STRING); 
    This replaces the old variables, sanitizes them (removes any HTML markup), and puts them into new variables.

    PHP Code:
    $headers "From: $from";
    $body "##################################################\nTHIS IS AN AUTOMATED EMAIL - DO NOT RESPOND\n##################################################\n\nSomebody just sent you a message using your contact form.\n\nName: $name_new\nEmail: $email_new\nMessage:\n$message_new\n\n"
    This is the actual email. $headers is going to be the From section, leave it as it is. The $body is what appears in the email. \n is a break. The variables are in it as well (notice we are using the sanitized ones). This is what the email would look like:


    PHP Code:
    mail($to$subject$body,$headers);
    ?>
    Normal HTML here 
    This is the final function that actually sends out the email. Now, you can put normal HTML after this, and that would be your 'Email sent!' page.

    This is a simple form, without validation or anti-spam. Just look up a Google search for that.
    Thanks a lottttt bud! You have covered everything I needed. I will add recaptcha tonight.
    My Blog- Let's Get Talking!
    Are you on Twitter? Let's become friends!

Similar Threads

  1. Can't Center a Form (PHP/HTML/CSS)
    By vectro in forum Web Design
    Replies: 3
    Last Post: 8 February, 2010, 20:50 PM
  2. I don't know PHP, how to make a web form?
    By crispin in forum Programming
    Replies: 3
    Last Post: 2 October, 2009, 10:49 AM
  3. Form Validation Help
    By Zash in forum Programming
    Replies: 6
    Last Post: 23 July, 2009, 06:30 AM
  4. How to use a contact form?
    By Logan in forum Blogging
    Replies: 5
    Last Post: 2 July, 2009, 22:12 PM
  5. Replies: 1
    Last Post: 14 May, 2009, 22:13 PM

Tags for this Thread

Bookmarks

Posting Permissions

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