I am using the following code to allow a user to submit an e-mail form to a specified address. The code works fine, however, the mail is being rejected with the following error:
553 5.1.8 <apache@atsomehost.com>... Domain of sender address
apache@atsomehost.com does not exist (in reply to MAIL FROM command))
Using the code below, how do instruct PHP to send e-mail from a valid e-mail account/domain?
-----------contact.php-------------------------------------------
<p><form method="post" action="sendeail.php">
<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>
<p>
<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
</p>
<p><font size="2" face="Arial, Helvetica, sans-serif">Your Name: <br />
<input type="text" name="visitor" size="35" />
<br />
Your Email:<br />
<input type="text" name="visitormail" size="35" />
<br />
<br />
CC Yourself? No
<input name="ccopy" type="radio" value="ccno" />
Yes
<input checked="checked" name="ccopy" type="radio" value="ccyes" />
<br />
<br />
Send To:<br />
<select name="attn" size="1">
<option value=" Sales and Billing ">Sales and Billing </option>
<option value=" General Question ">General Question </option>
</select>
<br />
<br />
Mail Message: </font><br />
<textarea name="notes" rows="6" cols="40"></textarea>
<br />
<input type="submit" value="Send Mail" />
<br />
</p>
</form>
------- sendeail.php-----------------------------------------------
<?php
$myemail = "specific@email.com";
$ccx = "";
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
}
if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2>Use Back - fill in all fields</h2>\n";
}
echo $badinput;
$todayis = date("l, F j, Y, g:i a") ;
$attn = $attn . "(" . $ccopy . ")" ;
$subject = $attn;
$notes = stripcslashes($notes);
$message = " $todayis [EST] \n
Attention: $attn \n
Message: $notes \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";
$from = "From: $visitormail\r\n";
if (($ccopy == "ccyes") && ($visitormail != ""))
mail($visitormail, $subject, $message, $from);
if ($myemail != "")
mail($myemail, $subject, $message, $from);
if ($ccx != "")
mail($ccx, $subject, $message, $from);
?>
<p align="center">
Date: <?php echo $todayis ?>
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )
<br />
Attention: <?php echo $attn ?>
<br />
Message:<br />
<?php $notesout = str_replace("\r", "<br/>", $notes);
echo $notesout; ?>
<br />
<?php echo $ip ?> <a href="contact.php"> Next Page </a>
Thank you