Forum Moderators: coopster

Message Too Old, No Replies

Emailing results from a form script

email results form script

         

matthewamzn

11:02 pm on Aug 9, 2005 (gmt 0)

10+ Year Member



The form script below is working for me. But I'm not sure how the sender information is gathered. When I finished filling out the form and click submit, an email is sent to the recipient (me). But when I open the email the sender information is:
"Nobody" <nobody@davinci.hmdnsgroup.com>

<html>
<head>
<title>Contact Form</title>
<body>
<?php
if ($_SERVER['REQUEST_METHOD']!= 'POST'){
$me = $_SERVER['PHP_SELF'];
?>
<form name="form1" method="post"
action="<?php echo $me;?>">
<table border="0" cellspacing="0" cellpadding="2">
<tr>
<td>Name:</td>
<td><input type="text" name="Name"></td>
</tr>
<tr>
<td>Subject</td>
<td><input type="text" name="Subject"></td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="address"></td>
</tr>
<tr>
<td>City</td>
<td><input type="text" name="city"></td>
</tr>
<tr>
<td>Province</td>
<td><input type="text" name="province"></td>
</tr>
<tr>
<td>Postal Code</td>
<td><input type="text" name="postalcode"></td>
</tr>
<tr>
<td>Stock Number</td>
<td><input type="text" name="stocknumber"></td>
</tr>
<tr>
<td valign="top">Message:</td>
<td><textarea name="MsgBody"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit"
value="Send"></td>
</tr>
</table>
</form>
<?php
} else {
error_reporting(0);
$recipient = 'example@yahoo.com';
$subject = stripslashes($_POST['Subject']);
$from = stripslashes($_POST['Name']);
$add = stripslashes($_POST['address']);
$city = stripslashes($_POST['city']);
$province = stripslashes($_POST['province']);
$postalcode = stripslashes($_POST['postalcode']);
$stocknumber = stripslashes($_POST['stocknumber']);
$msg = "Message from: $from\n\n$stocknumber\n\n$add\n\n$city\n\n$province\n\n$postalcode\n\n$stocknumber".stripslashes($_POST['MsgBody']);
if (mail($recipient, $subject, $msg))
echo nl2br("<b>Message Sent:</b>
To: $recipient
Subject: $subject
Message: Thank your submission.");
else
echo "Message failed to send";
}
?>
</body>
</html>

StupidScript

11:16 pm on Aug 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"nobody" is the "identity" of your web server, which is sending the mail. It's usually "nobody" or "apache" or somesuch. In the absence of a "real" sender, you're getting the result from the default sender (the server). The default sender is indicated in php.ini.

You may want to try something like this to get a different sender:

$from = "From: CoolDude <cooldude@example.com>";

then

mail($recipient, $subject, $msg, $from)

See the mail section of the manual [us2.php.net] for more optional headers.

[edited by: StupidScript at 11:21 pm (utc) on Aug. 9, 2005]

mrnoisy

11:18 pm on Aug 9, 2005 (gmt 0)

10+ Year Member



That address is probably coming from the server that's sending the mail.

Try adding header info:


<?php
} else {
error_reporting(0);
$recipient = 'example@yahoo.com';
$subject = stripslashes($_POST['Subject']);
$from = stripslashes($_POST['Name']);
$add = stripslashes($_POST['address']);
$city = stripslashes($_POST['city']);
$province = stripslashes($_POST['province']);
$postalcode = stripslashes($_POST['postalcode']);
$stocknumber = stripslashes($_POST['stocknumber']);
$msg = "Message from: $from\n\n$stocknumber\n\n$add\n\n$city\n\n$province\n\n$postalcode\n\n$stocknumber".stripslashes($_POST['MsgBody']);
$headers = "From: 'Example Business'<example@yahoo.com>\r\n" . "to: '$from' <$recipient>" . "\r\n" . "Reply-To: 'Example Business'<example@yahoo.com>\r\n" . 'X-Mailer: PHP/' . phpversion();
if (mail($recipient, $subject, $msg, $headers))
echo nl2br("<b>Message Sent:</b>
To: $recipient
Subject: $subject
Message: Thank your submission.");
else
echo "Message failed to send";
}
?>

matthewamzn

11:46 pm on Aug 9, 2005 (gmt 0)

10+ Year Member



Thanks