swiftmailer/swiftmailer — Issue #160: Upgraded to 4.1.5  getting FATAL ERROR on all websites
Author: Dave777
Created: 2012-01-21 09:48:14+00:00
State: open

Today I checked my registration script which sends out a confirmation email and noticed a warning:

Warning: The magic method __call() must have public visibility and cannot be static in /home/gigme77/public_html/lib/classes/Swift/Transport/EsmtpTransport.php on line 213

But the emails are at least delivered.

So I thought that it may be because I was using an older version of
the library and something has changed in php

So I downloaded the latest version: 4.1.5 and uploaded
the lib directory to my server.

Now I get a worse result: Fatal error: Uncaught exception and no email is sent.

This is the calling code:

$swift_path = $_SERVER['DOCUMENT_ROOT']."/lib/swift_required.php";
require_once("$swift_path");

$re1 = array("/\n/",
"/\s{2,}/",
"/>\s+/",
"/<[^>]+>/");

$re2 = array(" ",
" ",
" ",
" \n",
"");

$message_text = "text";

$message_text = preg_replace($re1,$re2,$message_html);

$transport = Swift_SmtpTransport::newInstance('mail.expressresponse.net', 25)
->setUsername('dave.exp526d')
->setPassword(xxxxxxxxxx')
;

$mailer = Swift_Mailer::newInstance($transport);

$message = Swift_Message::newInstance();

// set the sender
$message->setFrom(array($fm_email => $fm_name));

// set the recipient
$message->setTo(array($to => $contact));

// set the subject
$message->setSubject($subject);

// set the html body
$message->setBody($message_html, 'text/html');

// set the text body
$message->addPart($message_text, 'text/plain');

//Send the message
if (!$mailer->send($message, $failures)) {
// update failure database
$sql = "INSERT INTO `email_fail` (type,email,send_dt) VALUES ( '$send_type', '$to','$today')";
mysql_query($sql) or die("could not execute clients update query". mysql_error());
} // end if

?>

And here is the full fatal Error:

Fatal error: Uncaught exception 'Swift_TransportException' with message 'Failed to authenticate on SMTP server with username "dave.exp526d" using 2 possible authenticators' in /home/exp526d/public_html/lib/classes/Swift/Transport/Esmtp/AuthHandler.php:176 Stack trace: #0 /home/exp526d/public_html/lib/classes/Swift/Transport/EsmtpTransport.php(307): Swift_Transport_Esmtp_AuthHandler->afterEhlo(Object(Swift_SmtpTransport)) #1 /home/exp526d/public_html/lib/classes/Swift/Transport/AbstractSmtpTransport.php(124): Swift_Transport_EsmtpTransport->_doHeloCommand() #2 /home/exp526d/public_html/lib/classes/Swift/Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start() #3 /home/exp526d/public_html/send_email.php(70): Swift_Mailer->send(Object(Swift_Message), Array) #4 /home/exp526d/public_html/index.php(213): require('/home/exp526d/p...') #5 {main} thrown in /home/exp526d/public_html/lib/classes/Swift/Transport/Esmtp/AuthHandler.php on line 176

I noticed when searching for a solution to this problem that some are using the email format in the username.

So I changed the code to this:

$transport = Swift_SmtpTransport::newInstance('mail.expressresponse.net', 25)
->setUsername('dave@expressresponse.net')
->setPassword('xxxxxxxxxx')
;

BUT I still get a FATAL ERROR:

Fatal error: Uncaught exception 'Swift_TransportException' with message 'Failed to authenticate on SMTP server with username "dave@expressresponse.net" using 2 possible authenticators' in /home/exp526d/public_html/lib/classes/Swift/Transport/Esmtp/AuthHandler.php:176 Stack trace: #0 /home/exp526d/public_html/lib/classes/Swift/Transport/EsmtpTransport.php(307): Swift_Transport_Esmtp_AuthHandler->afterEhlo(Object(Swift_SmtpTransport)) #1 /home/exp526d/public_html/lib/classes/Swift/Transport/AbstractSmtpTransport.php(124): Swift_Transport_EsmtpTransport->_doHeloCommand() #2 /home/exp526d/public_html/lib/classes/Swift/Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start() #3 /home/exp526d/public_html/send_email.php(70): Swift_Mailer->send(Object(Swift_Message), Array) #4 /home/exp526d/public_html/index.php(213): require('/home/exp526d/p...') #5 {main} thrown in /home/exp526d/public_html/lib/classes/Swift/Transport/Esmtp/AuthHandler.php on line 176

Why is this ?
The user name is valid ... it worked fine with the previous /lib

In fact I have swapped them back and forth to check and I get the same results
without ANY change to my calling script.

I have looked at the usage of the classes and nothing appears to have
changed radically.

Have I missed something ?

How can I fix this ?

Thanks.