php-swiftmailerHow to get the error message in Swiftmailer?
Swiftmailer is a popular library for sending emails in PHP. To get the error message in Swiftmailer, you can use the getErrors()
method. This method will return an array of errors that occurred while sending the email.
Example code
<?php
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25);
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Test Subject')
->setFrom(array('[email protected]' => 'John Doe'))
->setTo(array('[email protected]', '[email protected]' => 'A name'))
->setBody('Here is the message itself');
try {
$result = $mailer->send($message);
} catch (Exception $e) {
$errors = $mailer->getErrors();
print_r($errors);
}
Output example
Array
(
[0] => Failed to authenticate on SMTP server with username "[email protected]"
[1] => SMTP server did not accept the password
)
The getErrors()
method will return an array of errors that occurred while sending the email. The array will contain a description of the error that occurred. This can be used to debug any issues that may arise while sending emails.
Helpful links
More of Php Swiftmailer
- How to set timeout with Swiftmailer?
- How to use SMTP with Swiftmailer?
- How to use TLS 1.2 with Swiftmailer?
- How to get the response code when using Swiftmailer?
- How to use Swiftmailer to send RFC 2822 compliant emails?
- How to configure Swiftmailer for Postfix?
- How to send emails in UTF8 using Swiftmailer?
- How to send emails to multiple recipients with Swiftmailer?
- How to set the port for Swiftmailer?
- How to enable TLS with Swiftmailer?
See more codes...