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 SMTP with Swiftmailer?
- How to set timeout with Swiftmailer?
- How to use TLS 1.2 with Swiftmailer?
- How to configure Swiftmailer for SMTP without authentication?
- How to send emails in UTF8 using Swiftmailer?
- How to get the error message in Swiftmailer?
- How to use Swiftmailer transport?
- How to use Swiftmailer with Symfony?
- How to use Swiftmailer to send RFC 2822 compliant emails?
- How to send emails with Swiftmailer?
See more codes...