yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.9k forks source link

ArgumentCountError Too few arguments to function Swift_Mime_SimpleMessage::__construct() #17917

Closed ghost closed 4 years ago

ghost commented 4 years ago

What steps will reproduce the problem?

I update Yii to 2.0.32 and now I can't send emails


    Yii::$app->mailer->compose()
        ->setFrom('from@mail.com')
        ->setTo('to@mail.com')
        ->setSubject('Message subject')
        ->setTextBody('Plain text content')
        ->setHtmlBody('<b>HTML content</b>')
        ->send();

What is the expected result?

Send email.

What do you get instead?

ArgumentCountError Too few arguments to function Swift_Mime_SimpleMessage::__construct(), 0 passed in /var/www/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Message.php on line 48 and at least 4 expected

Additional info

Q A
Yii version 2.0.32
PHP version 7.2.28
Operating system
yiisoft/yii2-swiftmailer ~2.1.0
ArgumentCountError: Too few arguments to function Swift_Mime_SimpleMessage::__construct(), 0 passed in /var/www/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Message.php on line 48 and at least 4 expected in /var/www/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMessage.php:33
Stack trace:
#0 /var/www/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Message.php(48): Swift_Mime_SimpleMessage->__construct()
#1 /var/www/vendor/yiisoft/yii2-swiftmailer/Message.php(434): Swift_Message->__construct()
#2 /var/www/vendor/yiisoft/yii2-swiftmailer/Message.php(66): yii\swiftmailer\Message->createSwiftMessage()
#3 /var/www/vendor/yiisoft/yii2-swiftmailer/Message.php(103): yii\swiftmailer\Message->getSwiftMessage()
#4 /var/www/backend/modules/autos/controllers/EmisionEspecialController.php(88): yii\swiftmailer\Message->setFrom('from@mail.com')
#5 [internal function]: backend\modules\autos\controllers\EmisionEspecialController->actionIndex()
#6 /var/www/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#7 /var/www/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#8 /var/www/vendor/yiisoft/yii2/base/Module.php(528): yii\base\Controller->runAction('', Array)
#9 /var/www/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction('autos/emision-e...', Array)
#10 /var/www/vendor/yiisoft/yii2/base/Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
#11 /var/www/backend/web/index.php(18): yii\base\Application->run()
#12 {main}
ghost commented 4 years ago

Sorry I think it's a swiftmailer issue, I fixed it following this temporary solution https://github.com/yiisoft/yii2-swiftmailer/issues/75#issuecomment-460994081