Help with a php email code

Discussion in 'PHP' started by dubs89, Dec 5, 2008.

  1. #1
    Hi,

    I am having problems with my Email code on this page:
    http://www.mmsracing.ca/contact.php

    The code works perfectly if all the info is entered correctly.

    However, if you don't enter into one of the text boxes or don't do a valid Email the page you bring it to is totally out of wack.

    If you enter in a real email address and don't leave any of the text boxes blank the page it brings you to is completely fine.
    (You might have to try it out to see what exactly I mean)

    Thank you
     
    dubs89, Dec 5, 2008 IP
  2. Ludatha

    Ludatha Peon

    Messages:
    35
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Could you post the PHP code?

    Make sure you are checking for empty fields:

    if(isset($_POST['name']) && isset($_POST['email']) && isset($_POST['message'])){
    mail(); // bla bla bla
    }
     
    Ludatha, Dec 5, 2008 IP
  3. dubs89

    dubs89 Peon

    Messages:
    231
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Here is the code:

    <?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 "<font color=white>Use Back - Enter valid e-mail</font>\n";
    $badinput ="\n";
    echo $badinput;
    die ("Go back");
    }

    if(empty($visitor) || empty($visitormail) || empty($notes )) {
    echo "<font color=white>Use Back - fill in all fields</font>\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("info@thedigitaloffering.com", $subject, $message, $from);

    ?>
     
    dubs89, Dec 9, 2008 IP
  4. Ludatha

    Ludatha Peon

    Messages:
    35
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You should not use $_POST['ip'] to get the users ip, to get their ip use:

    $ip = $_SERVER['REMOTE_ADDR'];

    The same goes for
    $httpref = $_POST['httpref'];
    $httpagent = $_POST['httpagent'];

    Also you should take this line out:
    $attn = $attn ;
     
    Ludatha, Dec 10, 2008 IP
  5. dubs89

    dubs89 Peon

    Messages:
    231
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I changed that but still no luck...
     
    dubs89, Dec 29, 2008 IP