I am trying to setup PHP to send email, from a project in Sams - Teach
Yourself PHP, MySQL and Apache in 24 Hours.chm. (newbie fodder)
The program appears to run OK but the email does not get delivered. The
program shows the email addresses that the email was supposedly sent to.
My email progress indicator shows the mail going out but it never gets to any of
it's destinations.
I think I have configured PHP 5.0.4, and Apache 2.0.54 correctly. Why else would
the email show that it's sending???
I also have MySQL 5.04. but I don't see anything in MySQL to set for email.
I am confused with:
; For Win32 only.
sendmail_from =
and
DEFAULT_SENDMAIL_PATH
in php.ini. How should these be set?
Here is the listing. Can anyone see something wrong here?
Any help will be greatly appreciated. TIA
<?php
if ($POST[op] != "send") {
//haven't seen the form, so show it
print "
<HTML>
<HEAD>
<TITLE>Send a Newsletter</TITLE>
</HEAD>
<BODY>
<h2>Send a Newsletter</h2>
<form method=\"post\" action=\"$SERVER[PHP_SELF]\">
<P><strong>Subject:</strong><br>
<input type=\"text\" name=\"subject\" size=30></p>
<P><strong>Mail Body:</strong><br>
<textarea name=\"message\" cols=50 rows=10 wrap=virtual></textarea>
<input type=\"hidden\" name=\"op\" value=\"send\">
<p><input type=\"submit\" name=\"submit\" value=\"Send It\"></p>
</FORM>
</BODY>
</HTML>";
} else if ($POST[op] == "send") {
//want to send form, so check for required fields
if (($POST[subject] =="") || ($_POST[message] == "")) {
header("Location: sendmymail.php");
exit;
}
// Connect to database, and select table.
include ("../docs/DB01.inc");
//get emails from subscribers list
$sql = "select email from subscribers";
$result = mysql_query($sql,$conn) or die(mysql_error());
//create a From: mailheader
$headers = "From: Your Mailing List <xxxxxxxx@addrress.net>\n";
//loop through results and send mail
while ($row = mysql_fetch_array($result)) {
set_time_limit(0);
$email = $row['email'];
mail("$email", stripslashes($POST[subject]), stripslashes($POST[message]), $headers);
print "newsletter sent to: $email<br>";
}
}
?>
Output...
newsletter sent to: xxxxxxxxx@netzero.net
newsletter sent to: xxxxxxxxx@yahoo.com
newsletter sent to: xxxxxxxxxs@adelphia.net
newsletter sent to: xxxxxxxxxs@hotmail.com
(names replaced with x)