I am modifying a script to email newsletter subscribers using a specified "from" return address instead of the "Nobody [nobody@rome.hostgo.com]" return address generated by the server. According to my hosting service, I can change this by adding a $from variable to my PHP code. Tried adding this in the html form and the php code below:
$sql = "select distinct email from newsletter";
// $sql = "select email from newsletter";
$rs = $db->query($sql);
// Paul added "$from", in mail() below
if (mysql_num_rows($rs)) {
while ($row = mysql_fetch_array($rs)) {
mail($from, $row["email"], $_POST["subject"], $body);
}
}
}
?>
<form method="post">
<h2>Mailout</h2>
<p><label>From:</label>
<input type="text" name="from" /></p>
<p><label>Subject:</label>
<input type="text" name="subject" /></p>
<p><label>Newsletter Body:</label>
<textarea name="newsletter_body"></textarea></p>
<p><input type="submit" name="send" value="Send" class="button"></p>
</form>
Message comes back still with "Nobody [nobody@rome.hostgo.com]" as the sender. and my specified return address as the "Subject."
Two questions:
1) Can I, as my hosting service claims, change the return address assigned by default by the server.
2) What would I change in the above code to make this work properly?