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

Thread: Mail Form

  1. #1
    New Coder
    Join Date
    Jul 2007
    Posts
    56
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Unhappy Mail Form

    Well, In my php mail form whenever someone sends a message it's made so it sends their IP address aswell. Now, I want to find out the host name like in vBulliten. Is this possible?
    Code:
    <?php
    
    session_start();
      
    // get posted data into local variables
    $EmailFrom = "----------@gmail.com";
    $EmailTo = "-----------@gmail.com";
    $Subject = "Contact Form Submission";
    $Username = Trim(stripslashes($_POST['user'])); 
    $EmailAddress = Trim(stripslashes($_POST['addrss'])); 
    $gender = Trim(stripslashes($_POST['gen'])); 
    $browser1 = Trim(stripslashes($_POST['brwsr1'])); 
    $browser2 = Trim(stripslashes($_POST['brwsr2']));
    $browser3 = Trim(stripslashes($_POST['brwsr3']));
    $position = Trim(stripslashes($_POST['pos']));
    $other = Trim(stripslashes($_POST['other'])); 
    $summary = Trim(stripslashes($_POST['sum']));
    
    // validation
    if(!empty($Username) && !empty($EmailAddress) && !empty($summary) && 
    
    ($_SESSION['security_code'] == $_POST['security_code']) && 
    
    (!empty($_SESSION['security_code'])) )
    {
        // prepare email body text
        $Body = "
       REMOTE_ADDR: {$_SERVER['REMOTE_ADDR']}
        Username: $Username
        EmailAddress: $EmailAddress
        gender: $gender
        browser1: $browser1
        browser2: $browser2
        browser3: $browser3
        position: $position
        other: $other
        summary: $summary
        
        ";
        $success = mail($EmailTo, $Subject, $Body, "From: <" . $EmailFrom . ">");
        if ($success)
        {
            print "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">";
        }
        else
        {
            print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">";
        } 
        print "<meta http-equiv=\"refresh\" 
    
    content=\"0;URL=http://notre.pakman20.com/index.php\">";
        unset($_SESSION['security_code']);
        exit;
    }
    else
    {
        // meta refresh error
        print "<meta http-equiv=\"refresh\" content=\"0;URL=contact_error.php\">";
        exit;
    }

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    That is achieved by using $_SERVER['REMOTE_HOST'], or gethostbyaddr($_SERVER['REMOTE_ADDR']).

  • #3
    New Coder
    Join Date
    Jul 2007
    Posts
    56
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Inigoesdr View Post
    That is achieved by using $_SERVER['REMOTE_HOST'], or gethostbyaddr($_SERVER['REMOTE_ADDR']).
    For some reason it didn't work.
    Last edited by Notre; 11-09-2007 at 11:59 PM.

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Excellent. Perhaps next time you reply you can provide some input such as what didn't work, what errors you got, and what code you used.

  • #5
    New Coder
    Join Date
    Jul 2007
    Posts
    56
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Inigoesdr View Post
    Excellent. Perhaps next time you reply you can provide some input such as what didn't work, what errors you got, and what code you used.
    Of course, I used this "$_SERVER['REMOTE_HOST']" and put it below the REMOTE_ADDR. But when I tested it nothing showed up in that space on the email.

    Oh, and If you remember you helped me with almost the same thing a while ago. http://www.codingforums.com/showthre...727#post604727
    Last edited by Notre; 11-10-2007 at 12:32 AM.

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Ah, I thought it looked familiar.

    Try this:
    PHP Code:
    $hostname = !empty($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : gethostbyaddr($_SERVER['REMOTE_ADDR']);
        
    $Body "
        REMOTE_ADDR: {$_SERVER['REMOTE_ADDR']}
        REMOTE_HOST: $hostname
        Username: $Username
        EmailAddress: $EmailAddress
        gender: $gender
        browser1: $browser1
        browser2: $browser2
        browser3: $browser3
        position: $position
        other: $other
        summary: $summary
        
        "


  • #7
    New Coder
    Join Date
    Jul 2007
    Posts
    56
    Thanks
    8
    Thanked 0 Times in 0 Posts
    So, It would look like this?

    Code:
    <?php
    
    session_start();
      
    // get posted data into local variables
    $EmailFrom = "----------@gmail.com";
    $EmailTo = "-----------@gmail.com";
    $Subject = "Contact Form Submission";
    $Username = Trim(stripslashes($_POST['user'])); 
    $EmailAddress = Trim(stripslashes($_POST['addrss'])); 
    $gender = Trim(stripslashes($_POST['gen'])); 
    $browser1 = Trim(stripslashes($_POST['brwsr1'])); 
    $browser2 = Trim(stripslashes($_POST['brwsr2']));
    $browser3 = Trim(stripslashes($_POST['brwsr3']));
    $position = Trim(stripslashes($_POST['pos']));
    $other = Trim(stripslashes($_POST['other'])); 
    $summary = Trim(stripslashes($_POST['sum']));
    
    // validation
    if(!empty($Username) && !empty($EmailAddress) && !empty($summary) && 
    
    ($_SESSION['security_code'] == $_POST['security_code']) && 
    
    (!empty($_SESSION['security_code'])) )
    {
        // prepare email body text
    $hostname = !empty($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : gethostbyaddr($_SERVER['REMOTE_ADDR']);
        $Body = "
        REMOTE_ADDR: {$_SERVER['REMOTE_ADDR']}
        REMOTE_HOST: $hostname
        Username: $Username
        EmailAddress: $EmailAddress
        gender: $gender
        browser1: $browser1
        browser2: $browser2
        browser3: $browser3
        position: $position
        other: $other
        summary: $summary
        
        ";  
        $success = mail($EmailTo, $Subject, $Body, "From: <" . $EmailFrom . ">");
        if ($success)
        {
            print "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">";
        }
        else
        {
            print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">";
        } 
        print "<meta http-equiv=\"refresh\" 
    
    content=\"0;URL=http://notre.pakman20.com/index.php\">";
        unset($_SESSION['security_code']);
        exit;
    }
    else
    {
        // meta refresh error
        print "<meta http-equiv=\"refresh\" content=\"0;URL=contact_error.php\">";
        exit;
    }
    Now for some reason I keep getting the error which means somethings missing that's required... I'm wondering if it's in the like *required area.
    Last edited by Notre; 11-11-2007 at 02:40 AM.

  • #8
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Yeah, that code should work. Check the names of your form fields to make sure they're the same as what you're using and make sure the security code is being set.

  • #9
    New Coder
    Join Date
    Jul 2007
    Posts
    56
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Yeah, I can't find anything wrong, It just keeps feeding me the error.

  • #10
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Which error are you getting? (error.php or contact_error.php)

  • #11
    New Coder
    Join Date
    Jul 2007
    Posts
    56
    Thanks
    8
    Thanked 0 Times in 0 Posts
    It has to be the contact one because I don't have a regular error page.

  • #12
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Try this code, and when it doesn't work post the form.
    PHP Code:
    session_start();
      
    // get posted data into local variables
    $EmailFrom "----------@gmail.com";
    $EmailTo "-----------@gmail.com";
    $Subject "Contact Form Submission";
    $Username trim(stripslashes($_POST['user'])); 
    $EmailAddress trim(stripslashes($_POST['addrss'])); 
    $gender trim(stripslashes($_POST['gen'])); 
    $browser1 trim(stripslashes($_POST['brwsr1'])); 
    $browser2 trim(stripslashes($_POST['brwsr2']));
    $browser3 trim(stripslashes($_POST['brwsr3']));
    $position trim(stripslashes($_POST['pos']));
    $other trim(stripslashes($_POST['other'])); 
    $summary trim(stripslashes($_POST['sum']));

    // validation
    if(!empty($Username)
    && !empty(
    $EmailAddress)
    && !empty(
    $summary)
    && !empty(
    $_SESSION['security_code'])
    && 
    $_SESSION['security_code'] == $_POST['security_code'] )
    {
        
    // prepare email body text
        
    $hostname = !empty($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : gethostbyaddr($_SERVER['REMOTE_ADDR']);
        
    $Body "
        REMOTE_ADDR: {$_SERVER['REMOTE_ADDR']}
        REMOTE_HOST: $hostname
        Username: $Username
        EmailAddress: $EmailAddress
        gender: $gender
        browser1: $browser1
        browser2: $browser2
        browser3: $browser3
        position: $position
        other: $other
        summary: $summary
        
        "
    ;  
        
    $success mail($EmailTo$Subject$Body"From: <" $EmailFrom ">");
        if (
    $success)
        {
            print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">";
        }
        else
        {
            print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">";
        } 
        print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=http://notre.pakman20.com/index.php\">";
        unset(
    $_SESSION['security_code']);
        exit;
    }
    else
    {
        
    // meta refresh error
        
    print "<meta http-equiv=\"refresh\" content=\"0;URL=contact_error.php\">";
        exit;


  • Users who have thanked Inigoesdr for this post:

    Notre (11-14-2007)

  • #13
    New Coder
    Join Date
    Jul 2007
    Posts
    56
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Awesome dude, It worked. Have anymore things up your sleeve for my form? :P
    Last edited by Notre; 11-14-2007 at 01:33 AM.

  • #14
    New Coder
    Join Date
    Jul 2007
    Posts
    56
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Ok, I'm trying to make a new one...

    Code:
    <?php
    
    session_start();
      
    // get posted data into local variables
    $EmailFrom = Trim(stripslashes($_POST['from']));
    $EmailTo = Trim(stripslashes($_POST['to']));
    $Subject = Trim(stripslashes($_POST['sub']));
    $Bod = Trim(stripslashes($_POST['bod']));
    
    // validation
    if(!empty($Username) && !empty($EmailAddress) && !empty($Body) 
    
    
        // prepare email body text
        $Body = "$Bod
        ";
    
        $success = mail($EmailTo, $Subject, $Body, "From: <" . $EmailFrom . ">");
        if ($success)
        {
            print "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">";
        }
        else
        {
            print "<meta http-equiv=\"refresh\" content=\"0;URL=contact_error.php\">";
        } 
        ?>
    But this time I need to be able to input the email and the email it will go to from the form itself. Would this work along with this(see below)? Because I keep getting a "Parse error: parse error, unexpected T_VARIABLE in /home/content/p/a/k/pakman20/html/notre/mail2.php on line 16"

    Code:
    <font size="1" face="arial"><form name="reg" method="POST" action="mail2.php">
    
    
       <center>   <p><b>Email From:</b><br />
          <input type="text" size="20" name="from" />
          <p><b>Email To:</b><br />
    
          <input type="text" size="20" name="to" />
          <p><b>Subject:</b><br />
    <input type="text" size="20" name="sub" />
          <p><b>Body:</b><br />
        <textarea rows="5" cols="30" name="bod"></textarea></font><font size="1" face="Arial">
    <p><input type=reset value="Reset"><input type="submit" value="Submit"></font>
             </form>
    <p></center>
    Last edited by Notre; 11-14-2007 at 02:22 AM.

  • #15
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    PHP Code:
    session_start();
      
    // get posted data into local variables
    $EmailFrom trim(stripslashes($_POST['from']));
    $EmailTo trim(stripslashes($_POST['to']));
    $Subject trim(stripslashes($_POST['sub']));
    $Bod trim(stripslashes($_POST['bod']));

    // validation
    if(!empty($EmailFrom) && !empty($EmailTo) && !empty($Bod))
    {
        
    // prepare email body text
        
    $Body "$Bod
        "
    ;

        
    $success mail($EmailTo$Subject$Body"From: <" $EmailFrom ">");
        if (
    $success)
        {
            print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">";
        }
        else
        {
            print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=contact_error.php\">";
        }



  •  

    Posting Permissions

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