Swiftmailer will not send email, no errors reported

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?

Have you checked Yii logs and webserver log file?

You should check your SMTP port, by default, SSL is 465.

Thank you both! Good catch on the Port number. I’ve updated that to 465. The behavior has not changed.

I’ve found the Yii mail log for my latest test. It says Successfully sent: Yes.

Also, my Yii log and nginx log are not reporting any errors or warnings for this action.

It seems to me that Yii and nginx think they are doing their jobs correctly. Is there anywhere else I should be looking?

Here’s the full text of the Yii mail log:

Headers Message-ID: <71d52c7c1809bfcd64cd217ca58e828d@sasha.dev>

Date: Thu, 30 Oct 2014 21:00:57 +0000

Subject: An apology has been issued for one of your reports.

From: ***

To: ***

MIME-Version: 1.0

Content-Type: multipart/alternative;

boundary="=swift_v4_1414702857_169561f016c4dec690c4771c0b9e4dda="

From ***

To ***

Charset utf-8

Time Oct 30, 2014, 9:00:57 PM

Subject An apology has been issued for one of your reports.

Text body Testing with new email address.

Successfully sent Yes

Reply (not set)

Bcc (not set)

Cc (not set)

File Download eml

Figured it out, sort of. If I move the mailer config to my application-specific main.php config, the emails are successfully delivered.

When I comment out email configuration completely, Yii still says that the emails are sent successfully. This seems to be a bug.