Menu

#15 mass mailing with PHP

open
nobody
None
5
2005-07-22
2005-07-22
Anonymous
No

i used the following to send mails to about 5000
arbitrary mailing addresses. it basically works like this."

1) Fist it sends me a mail "MAIL 1" specifying the time
of sending.
2) Then it proceeds to send the 5000 mails refreshing
after every 200 mails.
3) after all mails are sent, it send me another mail
telling me all the files are sent.

The problem is, though all mails are sent, (i.e. no eroor
messages are printed and the code
executes 'echo "<br><b> 2nd mail sent to
samyak</b><p>"; ' i dont get the second mail. ( i did
get 1st mail however.

<?php
ini_set("safe_mode","false");
ini_set("max_execution_time","2000");

define ("MAX_AT_A_TIME",200);

if (isset($_GET['index'])){
$i= $_GET['index'] * MAX_AT_A_TIME;
$next = $_GET['index'] +1;
}
else //sending first mail to me
{
$date= date("l dS of F Y h:i:s A");

if (mail ("samyak@hotmail.com","First mail again","Mail
sent at".$date,$headers))
echo "<br><b> First mail sent to amit at
$date</b><p>";
else
echo "<br><b>Couldnt even sent first mail</b><p>";

$i=0;
$next = 1;
}
$last = $i+ MAX_AT_A_TIME;

echo "<h2><i>Starting mail sender</i></h2>";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-
1\r\n";
$headers .= "From: test\r\n";

//sending 200 mails at a time
for (;$i<$last;$i++){
$to = "test".$i."@hotmail.com";
echo "$i \t";
$subject="Mail test";
$body = "Sending the 5000 mails";

if (!mail($to,$subject,$body,$headers)) {
echo "Couldn't send mail to $to \t";
//break;
}

}
//if all 500 mails is sent send me another mail

if ($last >= 5000) {
echo "<b><u><i>All 5000 mails are sent</i</u></b>";
$date= date("l dS of F Y h:i:s A");
if (mail ("samyak@hotmail.com","All 5000 mails are
sent again-- ","I Completed sending mails sent
at".$date,$headers))
echo "<br><b> 2nd mail sent to samyak</b><p>";
else
echo "<br><b>Couldnt send 2nd mailto amit</b><p>";
}
else {
echo "Sleeping for 5 seconds";
sleep(5); //ensurig the ISP has no problem queing all
the mails
echo "<META http-equiv=\"refresh\"
content=\"0;URL=mail.php?index=$next\">"; //
refreshing to send another 200 mails.}

?>

Discussion


Log in to post a comment.