I’m attempting to send an email through an SMTP relay. The send() method of the mailer class returns true, but the email is not received, and my SMTP email address does not log a sent email. An EML file appears in my runtime/mail folder, and it appears to have the correct headers. I have tried executing this code from two different environments (locally and on Media Temple), and with both Gmail and Media Temple SMTP servers, and both behave the same way. Here is my setup.
common/config/main.php:
'components' => [
...
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport'=>false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => '****.accessdomain.com',
'username' => '****',
'password' => '****',
'port' => '456',
'encryption' => 'ssl',
]
],...
And my functional code:
// email the reporter
$message = Yii::$app->mailer->compose()
->setFrom('***')
->setTo($report->user->email)
->setSubject('An apology has been issued for one of your reports.')
->setTextBody($apology->comment)
->setHtmlBody('<p>' . $apology->comment . '</p>');
if (!$message->send()) {
$session->setFlash('error', 'An error occured while attempting to send your apology.');
$apology->delete();
} else {
$session->setFlash('success', 'Your apology has been sent.');
}
Is there anyway to catch errors that might be occurring? Any recommendations of where to look next?