D
D
dud0ser2017-06-27 22:17:52
Yii
dud0ser, 2017-06-27 22:17:52

Can't send email in yii2, what's the problem?

I just studied Yii2 and am writing a store, when placing an order, what the user ordered should be sent to the user’s mail, but for some reason I can’t send an email. The most incomprehensible thing for me is that during development, when enabled , the mail folder is created and the letter itself. but as soon as I put ' , then I get this error: Swift_TransportException here are the logs:'useFileTransport' => true,useFileTransport' => false

20:58:20.634 error Swift_TransportException exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.ukr.net [������ ��������� �������� �� ���� ����������, ��.�. �� ������ �������� �� �������� ���� �� ������ ���� ������ �, ��� ��� ��������� ��� ������������� ���������� ��-�� �� ������� ������� ��� ����������� ��������.
#10060]' in C:\OpenServer\domains\shop\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php:268
Stack trace:
#0 C:\OpenServer\domains\shop\vendor\swiftmailer \swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php(62): Swift_Transport_StreamBuffer->_establishSocketConnection()
#1 C:\OpenServer\domains\shop\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php(113): Swift_Transport_StreamBuffer->initialize(Array)
#2 C:\OpenServer\domains\shop\ vendor\swiftmailer\swiftmailer\lib\classes\Swift\Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start()
#3 C:\OpenServer\domains\shop\vendor\yiisoft\yii2-swiftmailer\Mailer.php(146) : Swift_Mailer->send(Object(Swift_Message))
#4 C:\OpenServer\domains\shop\vendor\yiisoft\yii2\mail\BaseMailer.php(262): yii\swiftmailer\Mailer->sendMessage(Object(yii\ swiftmailer\Message))
#5 C:\OpenServer\domains\shop\vendor\yiisoft\yii2\mail\BaseMessage.php(48): yii\mail\BaseMailer->send(Object(yii\swiftmailer\Message))
#6 C:\OpenServer\domains\shop\controllers\CartController.php(74): yii\mail\BaseMessage->send()
#7 [internal function]: app\controllers\CartController->actionView()
#8 C :\OpenServer\domains\shop\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
#9 C:\OpenServer\domains\shop\vendor\yiisoft\yii2\base\Controller. php(156): yii\base\InlineAction->runWithParams(Array)
#10 C:\OpenServer\domains\shop\vendor\yiisoft\yii2\base\Module.php(523): yii\base\Controller->runAction ('view', Array)
#11 C:\OpenServer\domains\shop\vendor\yiisoft\yii2\web\Application.php(102): yii\base\Module->runAction('cart/view', Array)
#12 C:\OpenServer\domains\shop\vendor\yiisoft\yii2\base\Application.php(380): yii\web\Application->handleRequest(Object(yii\web\Request))
#13 C:\OpenServer \domains\shop\web\index.php(13): yii\base\Application->run()
#14 {main}

here is the code in config/web.php :
'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => false,
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.ukr.net',
                'username' => 'vlad_babin_2013',
                'password' => '*******',
                'port' => '993',
                'encryption' => 'ssl',
            ],
        ],

here is the code in the controller:
Yii::$app->mailer->compose('order', ['session' => $session])
        ->setFrom('[email protected]')
        ->setTo($order->email)
        ->setSubject('Заказ')
        ->send();

I have already used both gmail.com and mail.ru,
what should I do? I don't understand what is wrong.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dud0ser, 2017-06-28
@dud0ser

Figured it out myself.
in config/web.php

'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.ukr.net',
               <b> 'username' => '[email protected]',</b>
                'password' => '******************',
                'port' => '465',
                'encryption' => 'ssl',
            ],

it is the username field that needs to be pointed to simply (in my case) vlad_babin_2013
and you need to specify the full address! (in my case) [email protected]
and in the documentation and everywhere on the Internet they write what is needed without @ukr.net, but it didn’t work for me (I tried both mail.ru and gmail.com)

�
Дмитрий, 2017-06-28
@slo_nik Куратор тега Yii

Доброй ночи.
Попробуйте так:

'port' => '465',
 // 'encryption' => 'ssl',
// или замените на
'encryption' => 'tls',

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question