...

View Full Version : PHP Mail Form Incorrect



Notre
08-25-2007, 11:59 PM
Here's the code for my form...


<form method="POST" action="contactmail.php">

<font size="2" face="arial"
<p><b>*Username:</b><br>
<input type="text" name="Username">
<p><b>*Email Address:</b><br>
<input type="text" name="EmailAddress">
<p><b>Gender:</b><br><input type="radio" name="gender" value="Male">Male
<br><input type="radio" name="gender" value="Female">Female
<p><b>Browsers:</b><br>
<input type="checkbox" name="browsers" value="Firefox" />Firefox<br>
<input type="checkbox" name="browsers" value="Internet Explorer/Netscape"

/>IE/Netscape<br>
<input type="checkbox" name="browsers" value="Other" />Other<p>
<b>*Desired Position:</b><br>
<select name="Position">
<OPTION VALUE="Admin" NAME="Admin">Administrator</option>
<OPTION VALUE="Mod" NAME="Mod">Moderator</option>
<OPTION VALUE="Design" NAME="Design">Designer</option>
<OPTION VALUE="Other" NAME="Other">Other</option>
</select><p>
<b>Summary/Other Position Request:</b><br>
<textarea name="summary" rows="6" cols="20"></textarea>
<p><font size="1">*Required</font></p>
<p><input type="submit" name="submit" value="Submit"></font>

</form>

Here's the code for the php that it redirects to to send to our email system.


<?php

// get posted data into local variables
$EmailFrom = "--------------";
$EmailTo = "---------------";
$Subject = "Contact Form Submission";
$Username = Trim(stripslashes($_POST['Username']));
$EmailAddress = Trim(stripslashes($_POST['EmailAddress']));
$gender = Trim(stripslashes($_POST['gender']));
$browsers = Trim(stripslashes($_POST['browsers']));
$position = Trim(stripslashes($_POST['position']));
$summary = Trim(stripslashes($_POST['summary']));

// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}

// prepare email body text
$Body = "";
$Body .= "Username: ";
$Body .= $Username;
$Body .= "\n";
$Body .= "EmailAddress: ";
$Body .= $EmailAddress;
$Body .= "\n";
$Body .= "gender: ";
$Body .= $gender;
$Body .= "\n";
$Body .= "gender: ";
$Body .= $gender;
$Body .= "\n";
$Body .= "browsers: ";
$Body .= $browsers;
$Body .= "\n";
$Body .= "position: ";
$Body .= $position;
$Body .= "\n";
$Body .= "summary: ";
$Body .= $summary;
$Body .= "\n";




// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">";
}
?>

The problem is that the drop down selection menu doesn't show up in the email, and gender shows up twice. If someone could tell me how to correct this and possibly make it so that it obtains the users IP and sends it via email aswell. That would be magnificent. :thumbsup:

Notre
08-26-2007, 01:46 AM
Well, I'm not sure if bumping a topic is aloud on this forum even though it's not in the rules, So I decided to give it a shot.

Nightfire
08-26-2007, 02:13 AM
<select name="Position">
<OPTION VALUE="Admin">Administrator</option>
<OPTION VALUE="Mod">Moderator</option>
<OPTION VALUE="Design">Designer</option>
<OPTION VALUE="Other">Other</option>
</select>


Options don't have names.

Notre
08-26-2007, 02:28 AM
Uh, What do you mean? How would it show up in an email if it didn't have a name?

Disregard this thread, I'm getting help from a friend. XD

Nightfire
08-26-2007, 06:52 AM
You get it from the value. Call it by $position.

kiwibrit
08-26-2007, 11:25 AM
Notre, see W3C - Forms (http://www.w3.org/TR/html401/interact/forms.html#h-17.6).

Notre
08-26-2007, 09:46 PM
Ok, I fixed the HTML and PHP so they would actually work together, Now is it possible to get the IP from the person who submits a form on the HTML page without them knowing, and then have it entered into a hidden section on the form and sent through the php to the email address?

Inigoesdr
08-26-2007, 09:49 PM
You would get it when the form is submitted with $_SERVER['REMOTE_ADDR'].

Notre
08-26-2007, 09:51 PM
Yes, but the HTML would have to send the form and data to the php for processing right? So I would need it to embed in the form or something and send it to the php, wouldn't I?

Nightfire
08-26-2007, 09:53 PM
No you don't need to :)

Notre
08-26-2007, 09:55 PM
Aha, It worked but now how could I get it to actually require stuff? I keep getting blank emails.

Inigoesdr
08-26-2007, 10:13 PM
// validation
if (!empty($Username) && !empty($EmailAddress)) // etc.
{
//send mail
}
else
{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
You can use a number of functions besides empty() to check the variables, such as strlen(). Empty will return true if the value sent with the form is 0, false, or null.

You can do redirects with header() in PHP too, btw. As long as you haven't output anything before you try to use it.

Notre
08-26-2007, 10:14 PM
Aha, So I can just add stuff that I need.

So I suppose this would work...


// validation
if (!empty($Username) && !empty($EmailAddress)) // etc.
{
//send mail
$success = mail($EmailTo, $Subject, $Body, "From: <" . $EmailFrom . ">");
}
else
{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}

Inigoesdr
08-26-2007, 10:24 PM
I don't see any errors, so yes it should.

Notre
08-26-2007, 10:27 PM
It works, But if variable= something other than 0 or null It just goes to the php page, I need it to go back to my index.

Inigoesdr
08-26-2007, 10:28 PM
// validation
if (!empty($Username) && !empty($EmailAddress)) // etc.
{
//send mail
$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\">";
}
}
else
{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
I copied that if/else from your other post but it has error.php, not error.htm like the other meta refresh.

Notre
08-26-2007, 10:30 PM
One more favor if I could ask how to get a validation image [doesn't need to change] which if wrong it will show the error page.

Notre
08-27-2007, 01:19 AM
This is my original code...


<?php

// get posted data into local variables
$EmailFrom = "notredame000@gmail.com";
$EmailTo = "notredame000@gmail.com";
$Subject = "Contact Form Submission";
$_SERVER['REMOTE_ADDR'];
$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']));
$summary = Trim(stripslashes($_POST['sum']));

// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=contact_error.php\">";
exit;
}

// prepare email body text
$Body = "";
$Body .= "REMOTE_ADDR: ";
$Body .= $REMOTE_ADDR;
$Body .= "\n";
$Body .= "Username: ";
$Body .= $Username;
$Body .= "\n";
$Body .= "EmailAddress: ";
$Body .= $EmailAddress;
$Body .= "\n";
$Body .= "gender: ";
$Body .= $gender;
$Body .= "\n";
$Body .= "browser1: ";
$Body .= $browser1;
$Body .= "\n";
$Body .= "browser2: ";
$Body .= $browser2;
$Body .= "\n";
$Body .= "browser3: ";
$Body .= $browser3;
$Body .= "\n";
$Body .= "position: ";
$Body .= $position;
$Body .= "\n";
$Body .= "summary: ";
$Body .= $summary;
$Body .= "\n";


// validation
if (!empty($Username) && !empty($EmailAddress) && !empty($summary))// etc.
{
//send mail
$success = mail($EmailTo, $Subject, $Body, "From: <" . $EmailFrom . ">");
print "<meta http-equiv=\"refresh\" content=\"0;URL=http://notre.pakman20.com/index.php\">";
exit;
}
else
{
print "<meta http-equiv=\"refresh\" content=\"0;URL=contact_error.php\">";
exit;
}
?>

I tried to add this too it below the second //validation.


if(!empty($Username) && !empty($EmailAddress) && !empty($summary) && ($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) )
{
$success = mail();
unset($_SESSION['security_code']);
}
else
{
// meta refresh error
}

My Try.

<?php

// get posted data into local variables
$EmailFrom = "notredame000@gmail.com";
$EmailTo = "notredame000@gmail.com";
$Subject = "Contact Form Submission";
$_SERVER['REMOTE_ADDR'];
$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']));
$summary = Trim(stripslashes($_POST['sum']));

// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=contact_error.php\">";
exit;
}

// prepare email body text
$Body = "";
$Body .= "REMOTE_ADDR: ";
$Body .= $REMOTE_ADDR;
$Body .= "\n";
$Body .= "Username: ";
$Body .= $Username;
$Body .= "\n";
$Body .= "EmailAddress: ";
$Body .= $EmailAddress;
$Body .= "\n";
$Body .= "gender: ";
$Body .= $gender;
$Body .= "\n";
$Body .= "browser1: ";
$Body .= $browser1;
$Body .= "\n";
$Body .= "browser2: ";
$Body .= $browser2;
$Body .= "\n";
$Body .= "browser3: ";
$Body .= $browser3;
$Body .= "\n";
$Body .= "position: ";
$Body .= $position;
$Body .= "\n";
$Body .= "summary: ";
$Body .= $summary;
$Body .= "\n";


// validation
if(!empty($Username) && !empty($EmailAddress) && !empty($summary) && ($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) )
{
$success = mail($EmailTo, $Subject, $Body, "From: <" . $EmailFrom . ">");
print "<meta http-equiv=\"refresh\" content=\"0;URL=http://notre.pakman20.com/index.php\">";
exit;
unset($_SESSION['security_code']);
}
else
{
// meta refresh error
print "<meta http-equiv=\"refresh\" content=\"0;URL=contact_error.php\">";
exit;
}
?>
But I don't know where to stop the second code on the first code.

If you could rush this because I'm hoping to finish tonight.

Inigoesdr
08-27-2007, 02:33 AM
This is what you're trying to do I guess?

<?php

// get posted data into local variables
$EmailFrom = "notredame000@gmail.com";
$EmailTo = "notredame000@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']));
$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
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
08-27-2007, 02:39 AM
I guess so, If it works I'll take it. :thumbsup: I went to this other forum for help with dynamic images, but the girl was being a real... Yeah you know.

EDIT: Sorry Mate, It didn't work, It keeps giving me error messages even though the code I entered is correct.

Inigoesdr
08-27-2007, 02:54 AM
What are the error messages?

Notre
08-27-2007, 03:01 AM
No, It's the normal one that says it's not entered.

Test it out if you want...

http://notre.pakman20.com/contact.php

Inigoesdr
08-27-2007, 03:19 AM
It's probably the security code because as far as I can see the fields are all there and named properly. Is the security code being set in CaptchaSecurityImages.php?

Notre
08-27-2007, 03:26 AM
What do you mean? I installed it right from that site (http://www.white-hat-web-design.co.uk/articles/php-captcha.php) and then edited the image file and colors. That's it so it should work, right? (You're my favourite coder so far. If you ever need graphics just PM me or something.)

EDIT: I probably got a sucky Captcha code.

Inigoesdr
08-27-2007, 03:34 AM
Put
session_start(); at the top of the contactemail.php page. (Yes it should work)

Notre
08-27-2007, 03:38 AM
That's already there, It was suggested to me by someone else. o.0

EDIT: I did that on the file, but I forgot to FTP it. Thanks man. It works perfectly now and I was just about to try another code. XD



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum