...

View Full Version : Mail Form



Notre
11-09-2007, 04:22 AM
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?


<?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;
}

Inigoesdr
11-09-2007, 05:50 AM
That is achieved by using $_SERVER['REMOTE_HOST'], or gethostbyaddr($_SERVER['REMOTE_ADDR']).

Notre
11-10-2007, 12:53 AM
That is achieved by using $_SERVER['REMOTE_HOST'], or gethostbyaddr($_SERVER['REMOTE_ADDR']).
For some reason it didn't work.

Inigoesdr
11-10-2007, 01:21 AM
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.

Notre
11-10-2007, 01:29 AM
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/showthread.php?p=604727#post604727

Inigoesdr
11-10-2007, 04:44 AM
Ah, I thought it looked familiar. :p

Try this:

$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

";

Notre
11-11-2007, 02:42 AM
So, It would look like this?



<?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.

Inigoesdr
11-11-2007, 05:31 AM
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.

Notre
11-12-2007, 03:25 AM
Yeah, I can't find anything wrong, It just keeps feeding me the error.

Inigoesdr
11-12-2007, 03:32 AM
Which error are you getting? (error.php or contact_error.php)

Notre
11-14-2007, 02:16 AM
It has to be the contact one because I don't have a regular error page.

Inigoesdr
11-14-2007, 02:24 AM
Try this code, and when it doesn't work post the form.

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;
}

Notre
11-14-2007, 02:29 AM
Awesome dude, It worked. Have anymore things up your sleeve for my form? :P

Notre
11-14-2007, 02:50 AM
Ok, I'm trying to make a new one...


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


<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>

Inigoesdr
11-14-2007, 04:11 AM
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\">";
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum