B
B
Benderm2018-03-06 15:01:54
Yii
Benderm, 2018-03-06 15:01:54

Why doesn't swiftmailer send via mail() in YII2?

Hello!
There was a problem sending emails in yii2.
The configuration is:
Yii 2.0.14.1.
swiftmailer 6.0.2.
PHP 7.1.
When sending on local, error prntscr.com/ink2wj
When sending on the server, the send function returns false. There are no errors in the logs.
I send an email like this:

$mail = Yii::$app->mailer->compose()
    ->setFrom('тут email')
    ->setTo('тут email')
    ->setSubject('Тема сообщения')
    ->setTextBody('Текст сообщения')
    ->setHtmlBody('<b>текст сообщения в формате HTML</b>')
    ->send();

In the config, the following settings:
'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
        ],

If you write "yiisoft/yii2-swiftmailer": "~2.0.0" in composer.json, then version 5.4 and everything works.
What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-03-06
@slo_nik

Good afternoon.
Look in the runtime/mail directory if 'useFileTransport' => true.
For sending mail to work, you need to configure swiftmailer Something
like this:

'transport' => [
                        'class' => 'Swift_SmtpTransport',
                        'host' => // mail host,
                        'port' => // port,
                        'username' => // login mail,
                        'password' => // pass mail,
                        //'encryption' => 'ssl'
                    ]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question