Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-09-2007, 03:22 AM   PM User | #1
Notre
New Coder

 
Join Date: Jul 2007
Posts: 56
Thanks: 8
Thanked 0 Times in 0 Posts
Notre is an unknown quantity at this point
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;
}
Notre is offline   Reply With Quote
Old 11-09-2007, 04:50 AM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
That is achieved by using $_SERVER['REMOTE_HOST'], or gethostbyaddr($_SERVER['REMOTE_ADDR']).
Inigoesdr is offline   Reply With Quote
Old 11-09-2007, 11:53 PM   PM User | #3
Notre
New Coder

 
Join Date: Jul 2007
Posts: 56
Thanks: 8
Thanked 0 Times in 0 Posts
Notre is an unknown quantity at this point
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..
Notre is offline   Reply With Quote
Old 11-10-2007, 12:21 AM   PM User | #4
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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.
Inigoesdr is offline   Reply With Quote
Old 11-10-2007, 12:29 AM   PM User | #5
Notre
New Coder

 
Join Date: Jul 2007
Posts: 56
Thanks: 8
Thanked 0 Times in 0 Posts
Notre is an unknown quantity at this point
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..
Notre is offline   Reply With Quote
Old 11-10-2007, 03:44 AM   PM User | #6
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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
    
    "

Inigoesdr is offline   Reply With Quote
Old 11-11-2007, 01:42 AM   PM User | #7
Notre
New Coder

 
Join Date: Jul 2007
Posts: 56
Thanks: 8
Thanked 0 Times in 0 Posts
Notre is an unknown quantity at this point
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..
Notre is offline   Reply With Quote
Old 11-11-2007, 04:31 AM   PM User | #8
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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.
Inigoesdr is offline   Reply With Quote
Old 11-12-2007, 02:25 AM   PM User | #9
Notre
New Coder

 
Join Date: Jul 2007
Posts: 56
Thanks: 8
Thanked 0 Times in 0 Posts
Notre is an unknown quantity at this point
Yeah, I can't find anything wrong, It just keeps feeding me the error.
Notre is offline   Reply With Quote
Old 11-12-2007, 02:32 AM   PM User | #10
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Which error are you getting? (error.php or contact_error.php)
Inigoesdr is offline   Reply With Quote
Old 11-14-2007, 01:16 AM   PM User | #11
Notre
New Coder

 
Join Date: Jul 2007
Posts: 56
Thanks: 8
Thanked 0 Times in 0 Posts
Notre is an unknown quantity at this point
It has to be the contact one because I don't have a regular error page.
Notre is offline   Reply With Quote
Old 11-14-2007, 01:24 AM   PM User | #12
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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;

Inigoesdr is offline   Reply With Quote
Users who have thanked Inigoesdr for this post:
Notre (11-14-2007)
Old 11-14-2007, 01:29 AM   PM User | #13
Notre
New Coder

 
Join Date: Jul 2007
Posts: 56
Thanks: 8
Thanked 0 Times in 0 Posts
Notre is an unknown quantity at this point
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..
Notre is offline   Reply With Quote
Old 11-14-2007, 01:50 AM   PM User | #14
Notre
New Coder

 
Join Date: Jul 2007
Posts: 56
Thanks: 8
Thanked 0 Times in 0 Posts
Notre is an unknown quantity at this point
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..
Notre is offline   Reply With Quote
Old 11-14-2007, 03:11 AM   PM User | #15
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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\">";
    }

Inigoesdr is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:41 AM.


Advertisement
Log in to turn off these ads.