I am fairly new to both swift and PHP, I have adapted a script example that Chris posted to handle a form. My adapted script should loop through approximately 400 email addresses in my database, but around about half way though running the script I get the IE "cannot display the webpage" screen.
I know that atleast 100 of the recipients receive the email because the guy who I built the site for gets his email and he is 107th in the database, but further than that I don't know how many subscribers are recieving the email.
I have posted the script below and wondered if anyone could see any obvious errors.
Any help would be gratefully appreciated.
Thank you.
Code: Select all
require_once "../Connections/connAgchem.php";
require_once "../lib/Swift.php";
require_once "../lib/Swift/Connection/SMTP.php";
require_once "../lib/Swift/Plugin/AntiFlood.php";
// Query database
mysql_select_db($database_connAgchem, $connAgchem);
$query = "SELECT Username FROM subscribers WHERE Email_Me = 'Y'";
$result = mysql_query($query) or die(mysql_error());
//Copy into global variables
$ProdGroup = $_POST['ProductGroupName'];
$Country = $_POST['Country'];
$ActiveIng = $_POST['ActiveIng'];
$Conc = $_POST['Concentration'];
$Formula = $_POST['Formula'];
$Tradename = $_POST['Tradename'];
$Type = $_POST['Supplier'];
$Quantity = $_POST['Quantity'];
$Region = $_POST['Country'];
$ID = $_POST['ID'];
$Status = $_POST['Sent'];
//Enable disk caching if we can
if (is_writable("/tmp"))
{
Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath("/tmp");
}
//Create a Swift instance
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
//Reconnect after 200 emails, but wait for 10 seconds first
$swift->attachPlugin(new Swift_Plugin_AntiFlood(100, 10), "anti-flood");
//Create the sender from the details we've been given
$sender =& new Swift_Address("webactivity@agchemaccess.co.uk");
//Create the message to send
$body = "The agrochemical shown below has recently been added to our on-line data base. As part of our AgChemConnect® service we are keeping you informed." . "\r\n" . "\r\n" . "Agrochemical: " . $ProdGroup . "\r\n" . "Active Ing: " . $ActiveIng . "\r\n" . "Trade Name: " . $Tradename . "\r\n" . "Concentration: " . $Conc . "\r\n" . "Quantity: " . $Quantity . "\r\n" . "Formula: " . $Formula . "\r\n" . "Region: " . $Region . "\r\n" . "Type: " . $Type . "\r\n" . "\r\n" . "For more information about this agrochemical please reply to this email, or telephone +44(0)1603 624413" . "\r\n" . "\r\n" . "Kind regards" . "\r\n" . "The AgChemAccess team" . "\r\n" . "\r\n" . "To unsubscribe from AgChemConnect® email alerts please update your web site profile at http://www.agchemaccess.co.uk";
$message =& new Swift_Message("New Agrochemical Added");
$message->attach(new Swift_Message_Part($body));
//Try sending the email
$recipients =& new Swift_RecipientList();
while ($row = mysql_fetch_array($result))
{
$recipients->addTo($row['Username']);
}
$sent = $swift->batchSend($message, $recipients, $sender);
//$sent = $swift->send($message, new Swift_Address($subEmail), $sender);
//Disconnect from SMTP, we're done
$swift->disconnect();
if ($sent)
{
header("Location: ./current_agchems.php");
exit();
}
else
{
header("Location: ./current_agchems.php?error=sending_failed");
exit();
}