Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jun 2009
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Post Easy Contact Form.

    Hey guys, i read endless times that people are going wrong with email forms... so i have a solution, Here is an easy quick tutorial on how to create a simple email form directing to the email address you wish.

    First create a " contact.php "
    PHP Code:
    <style type="text/css">
    .style1 {
        text-align: center;
    }
    </style>
    <div class="style1">
        <strong><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

        </strong>

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <strong>
    <title>Email Form </title>
    </strong>
    </head>
    <body style="background-color: #0000FF">

    </div>

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

    <div class="style1">
        <strong>

    <!-- DO NOT change ANY of the php sections -->
    <?php
    $ipi 
    getenv("REMOTE_ADDR");
    $httprefi getenv ("HTTP_REFERER");
    $httpagenti getenv ("HTTP_USER_AGENT");
    ?></strong> <strong>

    <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" /></strong> <strong>
    <br />
    Your Email:<br />
    <input type="text" name="visitormail" size="35" /></strong> <strong>
    <br /> <br />
    <br />
    Attention:<br />
    <select name="attn" size="1">
    <option value=" Sales and Billing ">Sales and Billing </option> 
    <option value=" General Support ">General Support </option> 
    <option value=" Technical Support ">Technical Support </option> 
    <option value=" Registration Issues ">Registration Issues </option> 
    </select></strong> <strong>
    <br /><br />
    Message:
    <br />
    <textarea name="notes" rows="4" cols="40"></textarea></strong> <strong>
    <br />
    <input type="submit" value="Send Mail" /></strong> <strong>
    <br />
        </strong></div>
    </form>

    </body>
    </html>
    Okay so the line where it says "<option value=" Sales and Billing ">Sales and Billing </option> " you can change the "Sales and Billing" to anything you want, the first "Sales and Billing" will appear if they select that into your inbox, the second one will be what the customers see. So pretty easy so far?

    Next create a " sendemail.php "
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>Reply</title>
    <style type="text/css">
    .style1 {
        color: #FF0000;
    }
    </style>
    </head>
    <body style="background-color: #0000FF">

    <!-- Reminder: Add the link for the 'next page' (at the bottom) --> 
    <!-- Reminder: Change 'YourEmail' to Your real email --> 

    <?php

    $ip 
    $_POST['ip']; 
    $httpref $_POST['httpref']; 
    $httpagent $_POST['httpagent']; 
    $visitor $_POST['visitor']; 
    $visitormail $_POST['visitormail']; 
    $notes $_POST['notes'];
    $attn $_POST['attn'];


    if (
    eregi('http:'$notes)) {
    die (
    "Do NOT try that! ! ");
    }
    if(!
    $visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,"."))) 
    {
    echo 
    "<h2>Oops! you did not fill in all the information please go back - Enter information</h2>\n"
    $badinput "<h2>Feedback was NOT submitted you shall now be re-directed back to the contact form.</h2>\n";
    echo 
    $badinput;
    die (
    "Hmm Error ");
    }

    if(empty(
    $visitor) || empty($visitormail) || empty($notes )) {
    echo 
    "<h2><center>Oops! you did not fill in all the information please go back - Enter valid information</center></h2>\n";
    die (
    "<center>Feedback was NOT submitted you shall now be re-directed back to the contact form.</center> "); 
    }

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

    $attn $attn 
    $subject $attn

    $notes stripcslashes($notes); 

    $message " $todayis [EST] \n
    Attention: $attn \n
    Message: $notes \n 
    From: $visitor ($visitormail)\n
    Additional Info : IP = $ip \n
    Browser Info: $httpagent \n
    Referral : $httpref \n
    "
    ;

    $from "From: ivii contact form";


    mail("!!!Your Email Here!!!"$subject$message$from);

    ?>

    <p align="center">
    Date: <?php echo $todayis ?> 
    <br />
    Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> ) 
    <br />

    Attention: <?php echo $attn ?>
    <br /> 
    Message:<br /> 
    <?php $notesout str_replace("\r""<br/>"$notes); 
    echo 
    $notesout?> 
    <br />
    <?php echo $ip ?> 

    <br /><br />
    <p align="center" class="style1">
    <strong>You shall now be re-directed to our home page.</strong></p> 
    <META HTTP-EQUIV="Refresh"
          CONTENT="3; URL=!!!Your Home Page!!!">
    </body>
    </html>
    Basicly you should change the sections where it says "!!!Your email here!!!" and also "!!!Your Home Page!!!" This shall you can change the number near the bottom of the code where it says "CONTENT="3;" how many ever seconds you want the person to wait until they are re-directed to a URL you wish.

    This was an easy simple tutorial, Thankyou for reading Hope it helped.
    Last edited by JasonReynolds; 01-20-2010 at 04:47 PM.

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    This needs to go in the PHP Snippet area.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #3
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    It also puts a style outside of the html tags and sticks the doctype in a div?
    Are you a Help Vampire?

  • #4
    New Coder
    Join Date
    Jun 2009
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tomws View Post
    It also puts a style outside of the html tags and sticks the doctype in a div?
    Sorry, i forgot to enter "<" let me add it to the code, That should work now

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    What is the point of this?
    Code:
    <META HTTP-EQUIV="Refresh"
          CONTENT="3; URL=!!!Your Home Page!!!">
    It can't go within the body like you have it and php does have refresh headers that allow you to use seconds to determine when to refresh.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #6
    Regular Coder
    Join Date
    Jul 2003
    Posts
    117
    Thanks
    0
    Thanked 17 Times in 17 Posts
    The From field of the email should be a proper email value. Some email servers will reject if it is not.
    PHP Code:
    $from "From: ContactForm<Your email here>"
    See: Why is my PHP script not sending emails? for details.
    Last edited by prasanthmj; 01-21-2010 at 03:38 AM.

  • #7
    New Coder
    Join Date
    Jun 2009
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts
    But even so it works. And i preffer META


  •  

    Posting Permissions

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