I use SwiftMailer to send simple mail. But when I use the SmtpTransport method (with hostname, username and password), I get the following error when using 2 possible authenticators. I was looking for a problem in stackoverflow but could not find a solution.
Fatal error: Uncaught exception 'Swift_TransportException' with message 'Failed to authenticate on SMTP server with username "xxx@yyyyyyyy.com" using 2 possible authenticators' in /home/yyyyyyyy/public_html/swiftmailer/lib/classes/Swift/Transport/Esmtp/AuthHandler.php:181 Stack trace:
/home/yyyyyyyy/public_html/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php(307): Swift_Transport_Esmtp_AuthHandler->afterEhlo(Object(Swift_SmtpTransport))
/home/yyyyyyyy/public_html/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(118): Swift_Transport_EsmtpTransport->_doHeloCommand()
/home/yyyyyyyy/public_html/swiftmailer/lib/classes/Swift/Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start()
/home/yyyyyyyy/public_html/testmail.php(51): Swift_Mailer->send(Object(Swift_Message))
My source is as follows. This source works fine in my local host, but not when it loads into a live environment.
$transport = Swift_SmtpTransport::newInstance("SMTPHOST", 25)
->setUsername("user")
->setPassword("pass");
$mailer = Swift_Mailer::newInstance($transport);
$to = "abc@aaa.com";
$subject = "Test Mail";
$email_body = "Hi Please confirm if you have received this email.";
$mail = Swift_Message::newInstance($subject)
->setFrom(array("research@lexingtonstudies.com"))
->setTo(array($to))
->setBcc(array("bcc1@aaa.com", "bcc2@bbb.com"))
->setBody($email_body, 'text/html');
$mailing_result = $mailer->send($mail);
I used 465 with ssl but got this error.
Swift_SmtpTransport::newInstance("SMTPHOST", 465, 'ssl')
Error
Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host SMTPHOST [Connection refused #111]' in /home/yyyyyyyy/public_html/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:265 Stack trace:
/home/yyyyyyyy/public_html/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php(62): Swift_Transport_StreamBuffer->_establishSocketConnection()
/home/yyyyyyyy/public_html/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(113): Swift_Transport_StreamBuffer->initialize(Array)
/home/yyyyyyyy/public_html/swiftmailer/lib/classes/Swift/Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start()
/home/yyyyyyyy/public_html/testmail.php(51): Swift_Mailer->send(Object(Swift_Message))
Please help me solve this problem.
source
share