I'm banging my head against a very odd problem. The code below sends emails to an array of recipients. If $test is set to "yes", I get the mails sent to me, for testing- this works fine. If it's set to "no", the mails are supposed to go to the recipients pulled from the database, but they don't. This is very confusing, because the only difference between testing or not testing is the size and contents of the $recipients array. The full database generated $recipients array can contain between 60 and 1300 addresses.
I am relaying the mail from our local server (where Swiftmailer is running) to our web and mail server using the SMTP connection method, and it's authenticating and working fine- as demonstrated by the fact that when $test=="yes" all works fine. My host has advised me that they are using Exim, and Courier (for authentication). They have also said that they do not limit email sending, so it's not being 'choked'. I've looked at the contents of the $recipients array produced in both cases, and it is a valid array of recipients. I've looked at the contents of $swift=>transactions, and it shows that sending fails with the first RCPT command:
[6] => Array ( [command] => RCPT TO: <fisrtrecipient@email.com> [time] => 0.01258800 1164906795 [response] => 421 Unexpected failure, please try later )
Here's the code:
Code: Select all
<?php
//set some variables
$hostname = 'myserver.co.uk';
$mails_in_batch = 49;
$cooloff_time = 30;
$textonly = "Your email client is not capable of showing HTML- please upgrade in order to view this email.";
$from = "update";
//are we testing or not?
$test="no";
//Load in the components
require('Swift/Swift.php');
require('Swift/Swift/Connection/SMTP.php');
require_once('Swift/Swift/Plugin/AntiFlood.php');
$swift = new Swift(new Swift_Connection_SMTP($hostname));
//49 mails per batch with a 30 second pause between batches
$swift->loadPlugin(new Swift_Plugin_AntiFlood($mails_in_batch, $cooloff_time));
//authenticate with the server
if ($swift->authenticate($from.'@myserver.co.uk', 'mypasswordhere')){
//do nothing
}else{
die("not authenticated");
}
//Make the script run until it's finished in the background
set_time_limit(0);
ignore_user_abort();
ob_flush();
flush();
//database connection
$conn = mysql_connect ("localhost", "myunamehere", "mypasswordhere") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("mydatabasename");
if($test=="no"){
$sqlstring_recipients = "SELECT * FROM mailinglist WHERE (RecipientType = 'customer') AND (IsActive = 1)";
$sql_recipients = mysql_query($sqlstring_recipients, $conn) or die(mysql_error());
while($row_recipients = mysql_fetch_assoc($sql_recipients)){
$recipients[]=$row_recipients['Email'];
}
}else{
$recipients=array("test@myserver.co.uk","myhotmailaddress@hotmail.com");
}
$subject = "Product Update ".date("d/m/Y",time());
$message = stripslashes($_REQUEST['body']);
$swift->addPart($textonly);
$swift->addPart($message,'text/html');
$swift->addHeaders("Return-Path: ".$from."@myserver.co.uk\r\n");
$swift->setReplyTo('"Sender Name" <'.$from.'@myserver.co.uk>');
$swift->send($recipients, '"Sender Name" <'.$from.'@myserver.co.uk>', $subject);
$swift->close();
?>Any help would be very very much appreciated!