What do wrong?
Copier with mailtrap.io Configuration for Yii
'Components' = & gt; [
.....
'Mail' = & gt; [
'Class' = & gt; 'Yii \ SwiftMailer \ Mailer',
'TRANSPORT' = & GT; [
'Class' = & gt; 'SWIFT_SMTPTRANSPORT',
'host' = & gt; 'smtp.mailtrap.io',
'username' = & gt; 'Uname',
'password' = & gt; 'Upass',
'port' = & gt; '587',
'Encryption' = & gt; 'TLS',
],
],
],
Next in the controller
$ this- & gt; mailer- & gt; compose ()
- & gt; setfrom ('[email protected] ')
- & gt; setto ('[email protected] ')
- & gt; SetSubject ('Email Sent from Yii2-SwiftMailer')
- & gt; sen ();
and when trying to perform I get
swift_transportException
Expected Response Code 220 But Got An Empty Response
I can not understand what the reason is.
PS: The project is deployed locally.
PSPS: just in case I will add composer.json here, because I use only the kernel Yii. Can you need to save?
{
"REQUIRE": {
"Yiisoft / Yii2": "^ 2.0",
"VKCOM / VK-PHP-SDK": "5.95.0",
"Yiisoft / Yii2-SwiftMailer": "^ 2.1"
},
"REQUIRE-DEV": {
"PHPUNIT / PHPUNIT": "4.8.28"
}
}
Answer 1
In general, the problem is due to incorrect injection in the controller constructor, i.e. Did this:
__ construct (..., mailer $ mailer, ..., ...)
At the same time, its configs prescribed in the config / web.php file in the Components section.
Made like this:
Yii :: $ App- & gt; mailer- & gt; compose (...
And everything worked