Forum Moderators: coopster

Message Too Old, No Replies

contact form woes

sending email from a webpage

         

fwordboy

1:03 pm on Jun 7, 2004 (gmt 0)

10+ Year Member



I have a php page with a contact form on it.
I can get it to send the email but it always says its from Nobody with email nobody@nowhere.com

here's my code


<?php
if (isset($HTTP_POST_VARS['submit'])) {

$subject=($HTTP_POST_VARS['title']);
$body=($HTTP_POST_VARS['message']);
$from=($HTTP_POST_VARS['sender']);
&sender_email=($HTTP_POST_VARS['email']);

mail('me@mydomain.com', $subject, $body, $from, &sender_email);

echo ' <h3>Your email has been sent</h3>
<p>Thanks '. ($HTTP_POST_VARS['name']) .'</p>
';
}
else{
?>
<form id="email" method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
<fieldset>
<label for="sender">Your name</label><input id="sender" name="sender"><br>
<label for="email">Your email</label><input id="email" name="email"><br>
<label for="title">Subject</label><input id="title" name="title"><br>
<label for="message">Message</label><textarea id="message" name="message" cols="1" rows="1"></textarea><br>
<input type="submit" id="submit" name="submit" value="send">
</fieldset>
</form>

please help me out.

dcrombie

1:33 pm on Jun 7, 2004 (gmt 0)



The mail() function doesn't work like that.
You need to RTM: mail [php.net]

fwordboy

1:54 pm on Jun 7, 2004 (gmt 0)

10+ Year Member



okay so i've fixed it now.

Edit:

no i haven't, sorry false alarm

Timotheos

3:42 pm on Jun 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you tried it according to what the php manual says under the mail function?

The additional_parameters parameter can be used to pass an additional parameter to the program configured to use when sending mail using the sendmail_path configuration setting. For example, this can be used to set the envelope sender address when using sendmail with the -f sendmail option. You may need to add the user that your web server runs as to your sendmail configuration to prevent a 'X-Warning' header from being added to the message when you set the envelope sender using this method. Example 3. Sending mail with extra headers and setting an additional command line parameter.

<?php
mail("nobody@example.com", "the subject", $message,
"From: webmaster@{$_SERVER['SERVER_NAME']}", "-fwebmaster@{$_SERVER['SERVER_NAME']}");
?>

fwordboy

8:46 am on Jun 8, 2004 (gmt 0)

10+ Year Member



so why doesn't this code work?


<?php
if (isset($HTTP_POST_VARS['submit'])) {

$subject=($HTTP_POST_VARS['title']);
$message=($HTTP_POST_VARS['message']).'\n '.($HTTP_POST_VARS['sender']).'\n '.($HTTP_POST_VARS['email']);
$headers .= '"From: '.($HTTP_POST_VARS['sender']).' <'.($HTTP_POST_VARS['email']). '>\r\n"';

mail('myemailaddress@server.com, $subject, $message, $headers);

echo ' <h3>Your email has been sent</h3>
<p>Thanks '. ($HTTP_POST_VARS['sender']) .'</p>
';
}
else{
?>

i get the email with the body conatining the message along with sender's name and email address but in the from box in my mailbox it says it from Nobody!

fwordboy

10:14 am on Jun 8, 2004 (gmt 0)

10+ Year Member



fixed it


$headers .= "From: \"".($HTTP_POST_VARS['sender'])."\" <".($HTTP_POST_VARS['email']).">\n";

thanks for everyone's help. i find php very difficult to learn,it still kicks perl's ass but i am yet to find tutorial (including the manual) that explains it in a way i can understand.