PDA

View Full Version : email form question


khorais
01-27-2006, 10:03 PM
Hi,
I have a contact form which I have forwarded to a non-HR/non-webmail e-mail account. I would like the received e-mail to contain the email address entered, not "Nobody" as it does now. Is this possible?


//My code

<? function show_form($email="",$message="",$subject="") { ?>
<form action="<? echo $PHP_SELF ?>" method="post">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="form_input">
<p>Your E-mail address: <input type=text name=email size=30 value="<? echo $email ?>"></p></td>
</tr>
<tr valign="top">
<td class="form_input"><p>Subject: <input type=text name=subject size=30 value="<? echo $subject ?>"></p></td>
</tr>
<tr valign="top">
<td class="form_input"><p>Message: <textarea rows=10 cols=50 name=message><? echo $message ?></textarea></p></td>
</tr>
<tr><td><input type=submit value="Send message"></td></tr>
</table>
</form>

<? }

if (!isset($email) or !isset($message)) {
show_form();
}
else {

//some form validation that isn't shown goes here

show_form($email,$message,$subject);
}
else {
if ( empty($subject) ) {
$subject="your email";
}

$sent = mail( "recipient@mail.com",
"Web site email: $subject",$message, "Message from: $email" );

if ( $sent ) {
echo "<h1>Your message has been sent.</h1>";
echo "Thank you, $email. <p>We'll
will read your email regarding
$subject and reply soon.</p>";
}
else {
echo "<h1>There is a Problem:</h1>
<p>The server was unable to send your
mail.</p>";
}
}
}
?>

//end code

Thanks for any help!

SnakEyez
01-27-2006, 11:27 PM
Yes it is very simple. All you need to do is modify the mail line to say From not Message from like you have it. This is because when you define headers they have a certain format which must be followed in order for the mail to be sent and displayed properly. So by improperly formatting the header, it is sent as a bad header that will return nobody.

Also one last thing you may not have noticed. I don't know if you have gotten your form to submit properly but it seems that you might run into issues because once you submit the form data it is sent via the post method yet when you check to see if the form has been submitted you check a locally defined variable of $email and not a variable from the post method which would be:

if(!isset($_POST['email']) || !isset($_POST['message']))

Hope this helps you out some and fixes your problem.

khorais
01-28-2006, 12:56 PM
Thanks for the help...that did the trick. :)