php-swiftmailerHow to access Swiftmailer logs?
Swiftmailer logs can be accessed by using the Swift_Plugins_Loggers_ArrayLogger
class. This class allows you to log messages and errors that occur during the sending of emails.
Example code
$logger = new Swift_Plugins_Loggers_ArrayLogger();
$mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
Output example
Array
(
)
The code above registers the logger plugin with the mailer. After sending the email, the log messages can be accessed using the getMessages()
method of the ArrayLogger
class.
Example code
$logs = $logger->getMessages();
Output example
Array
(
[0] => Connection could not be established with host smtp.example.com [Connection timed out #110]
[1] => Connection could not be established with host smtp.example.com [Connection timed out #110]
[2] => Connection could not be established with host smtp.example.com [Connection timed out #110]
[3] => Connection could not be established with host smtp.example.com [Connection timed out #110]
[4] => Connection could not be established with host smtp.example.com [Connection timed out #110]
)
The getMessages()
method returns an array of log messages. These messages can be used to debug any issues that may have occurred during the sending of emails.
Helpful links
More of Php Swiftmailer
- How to use TLS 1.2 with Swiftmailer?
- How to set timeout with Swiftmailer?
- How to get the response code when using Swiftmailer?
- How to set the reply to address in Swiftmailer?
- Swiftmailer usage example
- How to encrypt emails with SwiftMailer?
- How to configure Swiftmailer for SMTP without authentication?
- How to send emails in UTF8 using Swiftmailer?
- How to enable TLS with Swiftmailer?
- How to set the port for Swiftmailer?
See more codes...