Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP error from swiftMailer using Yii 2.0.x and PHP 7.4 #18262

Closed
miahm opened this issue Aug 28, 2020 · 2 comments
Closed

PHP error from swiftMailer using Yii 2.0.x and PHP 7.4 #18262

miahm opened this issue Aug 28, 2020 · 2 comments

Comments

@miahm
Copy link

miahm commented Aug 28, 2020

What steps will reproduce the problem?

The bug occurs when trying to use swiftMailer to send emails in PHP 7.4.x. Works fine in PHP 7.3.

The config:

'mailer' => [
                        'class' => 'yii\swiftmailer\Mailer',
                        'viewPath' => '@common/mail',
                        'transport' => [
                              'class' => 'Swift_SmtpTransport',
                              'host' => '***',
                              'username' => '***',
                              'password' => '***',
                              'port' => 465,
                              'encryption' => 'ssl',
                        ],
                        'useFileTransport' => false,
 ],

The code sample that generates the fatal error:

Yii::$app->mailer
     ->compose('userSignUp')
     ->setFrom('<email_address>')
     ->setTo('<email_address>')
     ->setSubject('Testing ...')
     ->send();

What is the expected result?

Should send an email to the recipient, optionally include HTML or text-only view templates.

What do you get instead?

PHP error -

[error][yii\base\ErrorException:8] yii\base\ErrorException: Trying to access array offset on value of type null in /home/Data/www/ga_websites/disyii2/vendor/egulias/email-validator/EmailValidator/Parser/Parser.php:147
Stack trace:
#0 /home/Data/www/ga_websites/disyii2/vendor/egulias/email-validator/EmailValidator/Parser/Parser.php(147): yii\base\ErrorHandler->handleError()
#1 /home/Data/www/ga_websites/disyii2/vendor/egulias/email-validator/EmailValidator/Parser/Parser.php(127): Egulias\EmailValidator\Parser\Parser->escaped()
#2 /home/Data/www/ga_websites/disyii2/vendor/egulias/email-validator/EmailValidator/Parser/LocalPart.php(57): Egulias\EmailValidator\Parser\Parser->isFWS()
#3 /home/Data/www/ga_websites/disyii2/vendor/egulias/email-validator/EmailValidator/EmailParser.php(48): Egulias\EmailValidator\Parser\LocalPart->parse()
#4 /home/Data/www/ga_websites/disyii2/vendor/egulias/email-validator/EmailValidator/Validation/RFCValidation.php(30): Egulias\EmailValidator\EmailParser->parse()
#5 /home/Data/www/ga_websites/disyii2/vendor/egulias/email-validator/EmailValidator/EmailValidator.php(37): Egulias\EmailValidator\Validation\RFCValidation->isValid()
#6 /home/Data/www/ga_websites/disyii2/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/IdentificationHeader.php(182): Egulias\EmailValidator\EmailValidator->isValid()
#7 /home/Data/www/ga_websites/disyii2/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/IdentificationHeader.php(128): Swift_Mime_Headers_IdentificationHeader->assertValidId()
#8 /home/Data/www/ga_websites/disyii2/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/IdentificationHeader.php(99): Swift_Mime_Headers_IdentificationHeader->setIds()
#9 /home/Data/www/ga_websites/disyii2/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/IdentificationHeader.php(75): Swift_Mime_Headers_IdentificationHeader->setId()
#10 /home/Data/www/ga_websites/disyii2/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleHeaderFactory.php(141): Swift_Mime_Headers_IdentificationHeader->setFieldBodyModel()
#11 /home/Data/www/ga_websites/disyii2/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleHeaderSet.php(115): Swift_Mime_SimpleHeaderFactory->createIdHeader()
#12 /home/Data/www/ga_websites/disyii2/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMimeEntity.php(217): Swift_Mime_SimpleHeaderSet->addIdHeader()
#13 /home/Data/www/ga_websites/disyii2/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMessage.php(53): Swift_Mime_SimpleMimeEntity->setId()
#14 /home/Data/www/ga_websites/disyii2/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Message.php(48): Swift_Mime_SimpleMessage->__construct()
#15 /home/Data/www/ga_websites/disyii2/vendor/yiisoft/yii2-swiftmailer/src/Message.php(437): Swift_Message->__construct()
#16 /home/Data/www/ga_websites/disyii2/vendor/yiisoft/yii2-swiftmailer/src/Message.php(66): yii\swiftmailer\Message->createSwiftMessage()
#17 /home/Data/www/ga_websites/disyii2/vendor/yiisoft/yii2-swiftmailer/src/Message.php(227): yii\swiftmailer\Message->getSwiftMessage()
#18 /home/Data/www/ga_websites/disyii2/vendor/yiisoft/yii2-swiftmailer/src/Message.php(213): yii\swiftmailer\Message->setBody()
#19 /home/Data/www/ga_websites/disyii2/vendor/yiisoft/yii2/mail/BaseMailer.php(201): yii\swiftmailer\Message->setHtmlBody()
#20 /home/Data/www/ga_websites/disyii2/frontend/views/accounts/dashboard.php(106): yii\mail\BaseMailer->compose()
#21 /home/Data/www/ga_websites/disyii2/vendor/yiisoft/yii2/base/View.php(348): require('/home/Data/www/...')
#22 /home/Data/www/ga_websites/disyii2/vendor/yiisoft/yii2/base/View.php(257): yii\base\View->renderPhpFile()
#23 /home/Data/www/ga_websites/disyii2/vendor/yiisoft/yii2/base/View.php(156): yii\base\View->renderFile()
#24 /home/Data/www/ga_websites/disyii2/vendor/yiisoft/yii2/base/Controller.php(409): yii\base\View->render()
#25 /home/Data/www/ga_websites/disyii2/frontend/controllers/AccountsController.php(238): yii\base\Controller->render()
#26 [internal function]: frontend\controllers\AccountsController->actionDashboard()
#27 /home/Data/www/ga_websites/disyii2/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#28 /home/Data/www/ga_websites/disyii2/vendor/yiisoft/yii2/base/Controller.php(180): yii\base\InlineAction->runWithParams()
#29 /home/Data/www/ga_websites/disyii2/vendor/yiisoft/yii2/base/Module.php(528): yii\base\Controller->runAction()
#30 /home/Data/www/ga_websites/disyii2/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction()
#31 /home/Data/www/ga_websites/disyii2/vendor/yiisoft/yii2/base/Application.php(386): yii\web\Application->handleRequest()
#32 /home/Data/www/ga_websites/disyii2/frontend/web/index.php(56): yii\base\Application->run()

Additional info

I have tried sending with HTML and Text views, only one view, no views - using setHtmlBody() and setTextBody() - all prodiced the same error.

Q A
Yii version 2.0.37
PHP version 7.4.9
Operating system CentOS 8
@bizley
Copy link
Member

bizley commented Aug 29, 2020

Like that stack says it's a problem in your 3rd party email validator and here is the PR fixing it. Update your software frequently.

@miahm
Copy link
Author

miahm commented Aug 29, 2020

Thank you for pointing out the other post. I was considering editing the line generating the error to check/bypass null values, though I was not sure whether the variable was designed to ever be null and allowing the code to continue with null would cause issues. Also, I am concerned that my edits will get wiped out if the codebase is ever updated.

I will continue with the edit for now.

@miahm miahm closed this as completed Aug 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants