Forum Moderators: coopster

Message Too Old, No Replies

Using phpmailer to send bulk mail

         

ColinJ

9:06 pm on Feb 24, 2003 (gmt 0)

10+ Year Member



Gidday Al,

I have written a script to open a mailing list and loop through extracting the email addresses. With each address it invokes an instance of php mailer and sends via smtp.

We limimt the list to only 50 names as I don't want to upset my host.

It appears though with as little as 50 names we may get as many as 80% send failures. While many of these are valid addresses.

What should I do,

Use smaller lists, build in a delay between each send so as not to overload the server.

<code>

<?
// load required class files
require("class.phpmailer.php");

// load required include files
include("commonhtml.php");

//establish common page defaults

$body_html = "";
$body_text = "";
$subject = "Newsletter No. 6";
$fromAddress = "someaddress@mydomainname.com";
$fromName = "My site";
$replyToAddress = "name@domain.au";
$file_html = "newsletter6.htm";
$file_text = "newsletter6.txt";

$lines = file($file_html);
if( count($lines) > 0 ){
while(list($k,$v)=each($lines)){
$body_html .= $v;
}
}
else{
die("Unable to Open $file_html.");
}

$body_text = "If you are reading this, your Email client was unable to display \n";
$body_text .= "our cool HTML newsletter. We have prepared an online version for you \n";
$body_text .= "it is available at \n";
$body_text .= "http://www.mydomain.au/index.htm?page=html/newsletter6.htm\n";

if(!($dataFile = fopen("maillist.txt","r+"))){

print("file could not be opened");

exit;

}

while(!feof($dataFile)){

// read a line from the file

$line = fgetss($dataFile, 255);
trim($line);

if(!($line=="")){

$arrayRecipients[] = $line;

}

}

HTML_Top("Send Mail");

?>
<p align="left">
<?

$arrFailures = array();

while(list($k, $v)=each($arrayRecipients)){

$mail = new phpmailer();

$mail->PluginDir = "./";

$mail->IsSMTP(); // send via SMTP
$mail->Host = "mail.mydomainname.com"; // SMTP servers
$mail->SMTPAuth = false; // turn on SMTP authentication

$mail->From = $fromAddress;
$mail->FromName = $fromName;
$mail->AddAddress($v);
$mail->AddReplyTo($replyToAddress);

$mail->WordWrap = 65; // set word wrap
$mail->IsHTML(true); // send as HTML

$mail->Subject = $subject;
$mail->Body = $body_html;
$mail->AltBody = $body_text;

if(!$mail->Send())
{
echo "$v - <font color=\"red\">send failure</font><br>";
}
else{
echo "$v - send successful<br>";
}

}

?>
</p>
<p align="left">
<a href="filename removed">Return to the Mailing List Manager</a>.
</p>
<?

HTML_Bottom();

?>

</code>

[edited by: jatar_k at 2:52 am (utc) on Feb. 25, 2003]
[edit reason] removed specifics [/edit]

jatar_k

2:54 am on Feb 25, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I would try a delay and see if that fixes the problem. You could also send one message instead of one to each person. Lump a big chunk into the bcc field and have some standard address in the to field.

ColinJ

3:03 am on Feb 25, 2003 (gmt 0)

10+ Year Member



Thank You,

using a delay has eliminated the problem.

I will take your suggestion onboard and perhaps use it in the future.

Colin