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 15 of 15
  1. #1
    New Coder
    Join Date
    Apr 2007
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Php contact form, not attaching data

    So I'm trying to make a simple contact form...
    My php knowledge is really basic, and almost non-existant.
    So I looked for a free script and adjusted it... But it seems something is nothing going as it's supposed to...
    Could somebody help me out with this?

    I was told my second php file (sendeail.php, isn't receiving the data as it should)
    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">

    <?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 ?>" />

    All fields are required to be filled in!<br /><br />

    Your Name: <br />
    <input type="text" name="visitor" size="35" />
    <br />
    Your Email:<br />
    <input type="text" name="visitormail" size="35" />
    <br />
    Your Gamename:<br />
    <input type="text" name="gamename" size="35" />
    <br />
    Your Age:<br />
    <input type="text" name="age" size="2" />
    <br />
    Your sex:<br />
    <select name="sex" size="1">
    <option value=" Male ">Male </option>
    <option value=" Female ">Female </option>
    </select>
    <br />
    Your favourite class:<br />
    <select name="class" size="1">
    <option value=" Engineer ">Engineer </option>
    <option value=" Medic ">Medic </option>
    <option value=" Field Ops ">Field Ops </option>
    <option value=" Covert Ops ">Covert Ops </option>
    <option value=" Soldier ">Soldier </option>
    </select>
    <br />

    Your favourite class:<br />
    <select name="class" size="1">
    <option value=" Engineer ">Engineer </option>
    <option value=" Medic ">Medic </option>
    <option value=" Field Ops ">Field Ops </option>
    <option value=" Covert Ops ">Covert Ops </option>
    <option value=" Soldier ">Soldier </option>
    </select>

    Why should we let you join KMD?:
    <br />
    <textarea name="notes" rows="4" cols="40"></textarea>
    <br />
    <input type="submit" value="Send Mail" />
    </form>

    </body>
    </html>

    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>


    <?php
    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;
    }
    if(empty(
    $visitor) || empty($visitormail) || empty($notes) || empty($gamename) {
    echo 
    "<h2>Use Back - fill in all fields</h2>\n";
    }

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

    $sex $sex;
    $class $class;
    $subject "Application";

    $notes stripcslashes($notes);

    $message " $todayis [EST] \n
    From: $visitor ($visitormail)\n
    Gamename: $gamename \n
    Age: $age \n
    Sex: $sex \n
    Favourite class: $class
    Why we should let him in KMD: $notes \n


    Additional Info : IP = $ip \n
    Browser Info: $httpagent \n
    Referral : $httpref \n
    "
    ;

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


    mail("myemail@gmail.com"$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>
    I've uploaded what I've got now here: http://www.ilfiorfiore.be/kmdtest/contact.php

    All help appreciated
    Thanks

  • #2
    New Coder
    Join Date
    Jun 2007
    Location
    VA
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You're not pulling the data from the $_POST array. So, if you need to get these values (Notes, Visitor, Visitormail, etc.) you have to have some way of referencing them in the page you're sending the "post" to. So, Here's an easy way of determining which variables that you're receiving on the page.

    in sendeail.php code in:

    print_r($_POST).

    This will print all of the values sent to this page from your form. Then you can see how you need to reference the variables in your sendeail.php script

  • #3
    New Coder
    Join Date
    Apr 2007
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Like I said, my knowledge of PHP is really limited. Could someone give me a solid example of how I call upon the data in $_POST, using my code, so I can do the rest myself?

    Thanks in advance...

  • #4
    New Coder
    Join Date
    Jun 2007
    Location
    VA
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>
    
    
    <?php
    // Begin Display of $_POST data
    print_r($_POST);
    echo "<br /><br />";
    // End 
    
    // The above code will display an array of the variables that were passed to this page in the superglobal $_POST.
    // If you add this to your code, and post the results from Array ( ... )
    // I can tell you what you're missing
    
    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;
    }
    if(empty($visitor) || empty($visitormail) || empty($notes) || empty($gamename) {
    echo "<h2>Use Back - fill in all fields</h2>\n";
    }
    
    $todayis = date("l, F j, Y, g:i a") ;
    
    $sex = $sex;
    $class = $class;
    $subject = "Application";
    
    $notes = stripcslashes($notes);
    
    $message = " $todayis [EST] \n
    From: $visitor ($visitormail)\n
    Gamename: $gamename \n
    Age: $age \n
    Sex: $sex \n
    Favourite class: $class
    Why we should let him in KMD: $notes \n
    
    
    Additional Info : IP = $ip \n
    Browser Info: $httpagent \n
    Referral : $httpref \n
    ";
    
    $from = "From: $visitormail\r\n";
    
    
    mail("myemail@gmail.com", $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>

  • #5
    New Coder
    Join Date
    Jun 2007
    Location
    VA
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The quickest way to reference the variables passed from the $_POST is like so:

    $visitor = $_POST['visitor'];

    that's assuming that there is piece of code in your form with the name="visitor"

    same applies for any other named input

  • #6
    New Coder
    Join Date
    Apr 2007
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    Array ( [ip] => 81.240.210.192 [httpref] => [httpagent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 [visitor] => Bernd [visitormail] => something@something.com [gamename] => threri [age] => 19 [sex] => Male [class] => Field Ops [notes] => fgfg )
    thanks for helping man

  • #7
    New Coder
    Join Date
    Apr 2007
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmmm...

    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>


    <?php
    // Begin Display of $_POST data
    print_r($_POST);
    echo 
    "<br /><br />";
    // End 
    $visitor $_POST['visitor'];
    $visitormail $_POST['visitormail'];
    $gamename $_POST['gamename'];
    $age $_POST['age'];
    $sex $_POST['sex'];
    $class $_POST['class'];
    $notes $_POST['notes'];

    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;
    }
    if(empty(
    $visitor) || empty($visitormail) || empty($notes) || empty($gamename) {
    echo 
    "<h2>Use Back - fill in all fields</h2>\n";
    }

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

    //$sex = $sex;
    //$class = $class;
    $subject "Application";

    $notes stripcslashes($notes);

    $message " $todayis [EST] \n
    From: $visitor ($visitormail)\n
    Gamename: $gamename \n
    Age: $age \n
    Sex: $sex \n
    Favourite class: $class
    Why we should let him in KMD: $notes \n


    Additional Info : IP = $ip \n
    Browser Info: $httpagent \n
    Referral : $httpref \n
    "
    ;

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


    mail("*********@gmail.com"$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="sendeail.php"> Next Page </a>
    </p>

    </body>
    </html>
    right, so that's what I did for all the variables... But it's still not doing anything, did I missinterpret what you said?

    http://www.ilfiorfiore.be/kmdtest/contact.php

  • #8
    New Coder
    Join Date
    Jun 2007
    Location
    VA
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so the easiest way to read the output is like this:

    Code:
    Array 
    ( 
    	[ip] => 81.240.210.192 
    	[httpref] => 
    	[httpagent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8.1.4) Gecko/20070515 firefox/2.0.0.4 
    	[visitor] => Bernd 
    	[visitormail] => something@something.com 
    	[gamename] => threri 
    	[age] => 19 
    	[sex] => Male 
    	[class] => Field Ops 
    	[notes] => fgfg 
    )
    The sqaure brackets [] contain the name of the Key and the arrow, => points to the value. so its

    Key => Value

    the Key will be visitor in --- <input type="text" name="visitor" />---whereas the value will be what is submitted by the user, unless a value is specified in the input tag on the form

    so if you want to reference the variables passed from your form, you can do one of two things:

    1. use $_POST['key'] where key is the name of the input on the form...or
    2. assign the $_POST['key'] to another variable in the beginning of your script like I mentioned above --> $visitor = $_POST['visitor'];

    With number 2, if you're referencing the variable multiple times, it just simplifies ref'ing that variable. Make Sense?
    Last edited by ddanatzko; 06-01-2007 at 11:03 PM. Reason: misinfo

  • #9
    New Coder
    Join Date
    Jun 2007
    Location
    VA
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what are you getting in your message?

  • #10
    New Coder
    Join Date
    Apr 2007
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Absolutely nothing, I'm getting a blank screen...
    And no e-mail.

  • #11
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    I'm getting a blank screen...
    PHP Code:
    error_reporting(E_ALL);
    ini_set("display_errors"true); 

  • #12
    New Coder
    Join Date
    Jun 2007
    Location
    VA
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry dude, I gotta run out for a few hours. I'll check back a little later to see if you've fixed the problem or not. If not, I'll dig through your code then.

  • #13
    New Coder
    Join Date
    Apr 2007
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks you two!
    But there seems to be a problem with my empty field checking code.

    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
    // Begin Display of $_POST data
    print_r($_POST);
    echo 
    "<br /><br />";
    // End 
    $visitor $_POST['visitor'];
    $visitormail $_POST['visitormail'];
    $gamename $_POST['gamename'];
    $age $_POST['age'];
    $sex $_POST['sex'];
    $class $_POST['class'];
    $notes $_POST['notes'];
    $ip $_POST['ip'];
    $httpref $_POST['httpref'];
    $httpagent $_POST['httpagent'];

    error_reporting(E_ALL);
    ini_set("display_errors"true);

    //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;
    //}
    //if(empty($visitor) || empty($visitormail) || empty($notes) || empty($gamename) {
    //echo "<h2>Use Back - fill in all fields</h2>\n";
    //}

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

    //$sex = $sex;
    //$class = $class;
    $subject "Application";

    $notes stripcslashes($notes);

    $message " $todayis [EST] \n
    From: $visitor ($visitormail)\n
    Gamename: $gamename \n
    Age: $age \n
    Sex: $sex \n
    Favourite class: $class
    Why we should let him in KMD: $notes \n


    Additional Info : IP = $ip \n
    Browser Info: $httpagent \n
    Referral : $httpref \n
    "
    ;

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


    mail("ramsbernd@gmail.com"$subject$message$from);

    ?>

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

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

    <br /><br />
    <a href="sendeail.php"> Next Page </a>
    </p>

    </body>
    </html>
    It works like that, but you're able to send empty fields... And that's not exactly what I'm trying to achieve.
    I do get an e-mail now, which is great...

    So, any suggestions for me?
    Thanks for that error checking code, fixed some minor errors I had.

  • #14
    New Coder
    Join Date
    Jun 2007
    Location
    VA
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try this and see if it works

    Code:
    <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 
    // Begin Display of $_POST data 
    print_r($_POST); 
    echo "<br /><br />"; 
    // End  
    $visitor = $_POST['visitor']; 
    $visitormail = $_POST['visitormail']; 
    $gamename = $_POST['gamename']; 
    $age = $_POST['age']; 
    $sex = $_POST['sex']; 
    $class = $_POST['class']; 
    $notes = $_POST['notes']; 
    $ip = $_POST['ip']; 
    $httpref = $_POST['httpref']; 
    $httpagent = $_POST['httpagent']; 
    
    error_reporting(E_ALL); 
    ini_set("display_errors", true); 
    
    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; 
    } 
    elseif(empty($visitor) || empty($visitormail) || empty($notes) || empty($gamename) { 
    echo "<h2>Use Back - fill in all fields</h2>\n"; 
    } 
    else{
    $todayis = date("l, F j, Y, g:i a") ; 
    
    //$sex = $sex; 
    //$class = $class; 
    $subject = "Application"; 
    
    $notes = stripcslashes($notes); 
    
    $message = " $todayis [EST] \n 
    From: $visitor ($visitormail)\n 
    Gamename: $gamename \n 
    Age: $age \n 
    Sex: $sex \n 
    Favourite class: $class 
    Why we should let him in KMD: $notes \n 
    
    
    Additional Info : IP = $ip \n 
    Browser Info: $httpagent \n 
    Referral : $httpref \n 
    "; 
    
    $from = "From: $visitormail\r\n"; 
    
    
    mail("ramsbernd@gmail.com", $subject, $message, $from); 
    
    ?> 
    
    <p align="center"> 
    Date: <?php echo $todayis ?> 
    <br /> 
    Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> ) 
    <br /> 
    
    Attention: <?php echo $notes ?> 
    <br /> 
    Message:<br /> 
    <?php $notesout = str_replace("\r", "<br/>", $notes); 
    echo $notesout; ?> 
    <br /> 
    <?php echo $ip ?> 
    
    <br /><br /> 
    <a href="sendeail.php"> Next Page </a> 
    </p> 
    
    </body> 
    </html> 
    <? }
    ?>

  • #15
    New Coder
    Join Date
    Apr 2007
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nope, gives me a blank page again :/ so weird...


  •  

    Posting Permissions

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