Answer the question
In order to leave comments, you need to log in
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}
'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',
],
],
Yii::$app->mailer->compose('order', ['session' => $session])
->setFrom('[email protected]')
->setTo($order->email)
->setSubject('Заказ')
->send();
Answer the question
In order to leave comments, you need to log in
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',
],
Доброй ночи.
Попробуйте так:
'port' => '465',
// 'encryption' => 'ssl',
// или замените на
'encryption' => 'tls',
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question