I use this php script to send out emails:
Code: Select all
function email($to, $subject, $body, $format='html', $replyto=E_FROM, $priority=3)
{
require_once "swift/Swift.php";
require_once "swift/Swift/Connection/SMTP.php";
$swift = new Swift(new Swift_Connection_SMTP("mail1.myserver.com"));
//Create the message
if ($format == 'html')
{
$email = new Swift_Message($subject, $body, "text/html");
} elseif ($format == 'plain') {
$email = new Swift_Message($subject, $body);
}
// set priority if it is not default 3 -- 1=high, 3=normal, 5=low
if ($priority != 3) $email->setPriority($priority);
$email->setReturnPath(E_BOUNCE);
$email->setReplyTo($replyto);
// from name is always E_FROM_NAME ($site_name)
$sender = new Swift_Address(E_FROM, E_FROM_NAME);
//Now check if Swift actually sends it
if ($swift->send($email, $to, $sender))
{
return true;
} else {
return false;
error();
}
$email->disconnect();
}The other info that may be helpful is we're running a dedicated LAMP server, it is running well under capacity.
Sporadically, I get this error:
Code: Select all
Fatal error: Uncaught exception 'Swift_ConnectionException' with message 'There was a problem reading line 1 of an SMTP response. The response so far was:<br />[]. It appears the connection has died without saying goodbye to us! Too many emails in one go perhaps? (fsockopen: #0) ' in /srv/www/www.mysite.com/public_html/includes/swift/Swift/Connection/SMTP.php:250
Stack trace:
#0 /srv/www/www.mysite.com/public_html/includes/swift/Swift.php(306): Swift_Connection_SMTP->read()
#1 /srv/www/www.mysite.com/public_html/includes/swift/Swift.php(427): Swift->command('??.', 250)
#2 /srv/www/www.mysite.com/public_html/includes/functions.php(1318): Swift->send(Object(Swift_Message), 'tandina@bigpond...', Object(Swift_Address))
#3 /srv/www/www.mysite.com/public_html/emails/item-won.php(14): email('tandina@bigpond...', 'You won FACETED...', '<html><body>?<h...')
#4 /srv/www/www.mysite.com/scripts/subscripts/closed-auctions.php(50): include('/srv/www/www.my...')
#5 /srv/www/www.mysite.com/scrip in /srv/www/www.mysite.com/public_html/includes/swift/Swift/Connection/SMTP.php on line 250