Results 1 to 3 of 3

Thread: beginner php form

  1. #1
    Join Date
    Oct 2007
    Posts
    47
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default beginner php form

    Hello there


    Below is the php form recommended to me to get a php form on my website. It definitely does the sort of thing I want - so thanks for the guidance there. It works great in its own right but when I come to placing the form within my existing website the action of sending 'sendeail.php' goes wrong.

    Is there anyway I could combine the code so it all takes place on one webpage rather than code.php opening sendail.php thus eliminating the problem.

    Cheers
    H



    ----
    E-mail Form Code (contact.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>Email Form </title>
    </head>
    <body>
    
    <form method="post" action="sendeail.php">
    
    <!-- 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 /> <br />
    <br />
    Attention:<br />
    <select name="attn" size="1">
    <option value=" Sales n Billing ">Sales n Billing </option> 
    <option value=" General Support ">General Support </option> 
    <option value=" Technical Support ">Technical Support </option> 
    <option value=" Webmaster ">Webmaster </option> 
    </select>
    <br /><br />
    Mail Message:
    <br />
    <textarea name="notes" rows="4" cols="40"></textarea>
    <br />
    <input type="submit" value="Send Mail" />
    <br />
    Free Code at: <a href="http://www.ibdhost.com/contact/">ibdhost.com/contact/</a>
    </form>
    
    </body>
    </html>
    Code for sendeail.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>Sendemail Script</title>
    </head>
    <body>
    
    <!-- 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>Use Back - Enter valid e-mail</h2>\n"; 
    $badinput = "<h2>Feedback was NOT submitted</h2>\n";
    echo $badinput;
    die ("Go back! ! ");
    }
    
    if(empty($visitor) || empty($visitormail) || empty($notes )) {
    echo "<h2>Use Back - fill in all fields</h2>\n";
    die ("Use back! ! "); 
    }
    
    $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: $visitormail\r\n";
    
    
    mail("YourEmail", $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 />
    <a href="contact.php"> Next Page </a> 
    </p> 
    
    </body>
    </html>
    Edit: Wrapped code in CODE tags
    Last edited by thetestingsite; 01-26-2008 at 03:12 PM.

  2. #2
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Not to make you do it all over again.. but look into DD_Form_Mailer

    This php gem is secure, uses required fields, etc.. out of the box it does everything you want, with step by step instructions. You can use it stand alone, or use the php include to put it on as many pages as you want.

    I have used this form for the last couple years and the improvements since then are great.

    It is pretty straight forward and works really well. One of the problems with any form that emails you is spam and bots. Since I installed this form I have reduced those by over 80%!

    Nice.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  3. #3
    Join Date
    Oct 2007
    Posts
    47
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Blizzard - you da man.

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
  •