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 log emails sent with Swiftmailer?
- How to use SMTP with Swiftmailer?
- How to use Swiftmailer to send RFC 2822 compliant emails?
- How to send emails to multiple recipients with Swiftmailer?
- How to configure Swiftmailer for SMTP without authentication?
- How to use Swiftmailer with Symfony?
- How to configure Swiftmailer logger?
- How to download Swiftmailer without Composer?
- How to set the reply to address in Swiftmailer?
- How to send multiple attachments with SwiftMailer?
See more codes...