I am using Swiftmailer PHP Version 4.3.0 and I want to send one email with 1500 email addresses in the BCC.
The limits on my server allow that I can send up to 10000 emails within 24h. I have not exceeded this limit.
However, when I try to send the email with Swiftmailer it returns the following error message (see below for details)
"421 too many messages in this connection "'
and only 999 emails from the 1500 email addresses in the BCC receive the email. I executed this experiment several times, also changing the number of emails in the BBC to 1000 or 2000 - each time exactly 999 emails go through. Is it possible that there is a limit somewhere in Swiftmailer which does not allow to set more then 999 email addresses in the BCC? If so, is it possible to change this limit? If not, what else could cause this problem?
Here is the complete error message from Swiftmailer:
exception 'Swift_TransportException' with message 'Expected response code 250 but got code "421", with message "421 too many messages in this connection "' in /is/htdocs/www/swift/lib/classes/Swift/Transport/AbstractSmtpTransport.php:386 Stack trace:
#0 /is/htdocs/www/swift/lib/classes/Swift/Transport/AbstractSmtpTransport.php(281): Swift_Transport_AbstractSmtpTransport->_assertResponseCode('421 too many me...', Array)
#1 /is/htdocs/www/swift/lib/classes/Swift/Transport/EsmtpTransport.php(245): Swift_Transport_AbstractSmtpTransport->executeCommand('MAIL FROM: executeCommand('MAIL FROM: _doMailFromCommand('[email protected]...')
#4 /is/htdocs/www/swift/lib/classes/Swift/Transport/AbstractSmtpTransport.php(466): Swift_Transport_AbstractSmtpTransport->_doMailTransaction(Object(Swift_Message), '[email protected]...', Array, Array)
#5 /is/htdocs/www/swift/lib/classes/Swift/Transport/AbstractSmtpTransport.php(178): Swift_Transport_AbstractSmtpTransport->_sendBcc(Object(Swift_Message), '[email protected]...', Array, Array)
#6 /is/htdocs/www/swift/lib/classes/Swift/Mailer.php(86): Swift_Transport_AbstractSmtpTransport->send(Object(Swift_Message), Array)
#7 /is/htdocs/www/swift/lib/swift_required.php(133): Swift_Mailer->send(Object(Swift_Message))
#8 /is/htdocs/www/mydomain.net/test.php(21): sendMessage()
#9 {main}
when executing this code:
/*
* Autoloader and dependency injection initialization for Swift Mailer.
*/
if (defined('SWIFT_REQUIRED_LOADED')) {
return;
}
define('SWIFT_REQUIRED_LOADED', true);
//Load Swift utility class
require dirname(__FILE__) . '/classes/Swift.php';
if (!function_exists('_swiftmailer_init')) {
function _swiftmailer_init()
{
require dirname(__FILE__) . '/swift_init.php';
}
}
//Start the autoloader and lazy-load the init script to set up dependency injection
Swift::registerAutoload('_swiftmailer_init');
sendMessage();
function sendMessage(){
try{
// LARGE ARRAY with 1500 entries
$bcc = array("[email protected]","[email protected]", ... , "[email protected]")
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('***', 25);
$transport->setUsername('***');
$transport->setPassword('***');
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create the message
$message = Swift_Message::newInstance();
// Give the message a subject
$message->setSubject("This is a test mail");
// Set the From address with an associative array
$message->setFrom(array('[email protected]' => 'My Name'));
$message->setTo("[email protected]");
$message->setBcc($bcc);
$message->setBody("Hi, this is a test mail. Enjoy.");
$result = $mailer->send($message);
echo "Success";
}
catch(Exception $exception)
{
echo $exception;
}
}