'Laravel 5.5 won't render email with PHP 7.4
I am trying to render an email in Laravel 5.5, but no matter what I do, I get the following error on render:
ErrorException (E_NOTICE) Trying to access array offset on value of type null
happens in \vendor\egulias\email-validator\EmailValidator\Parser\Parser.php
I am running php 7.4 and I believe the error does NOT happen on php 7.3.
web.php:
Route::get('scratch', function(){
$mail = new Test();
return $mail->render();
});
Test.php
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class Test extends Mailable
{
use Queueable, SerializesModels;
public $subscription;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('emails.test');
}
}
test.blade.php
Hello from world
I'm thinking this has to be an issue with Laravel 5.5 and PHP 7.4. I can change my version but I'd like to avoid that if possible. Upgrading Laravel won't work for this application.
edit
It's failing on this line in vendor\egulias\email-validator\EmailValidator\Parser\Parser.php
protected function escaped()
{
$previous = $this->lexer->getPrevious();
if ($previous['type'] === EmailLexer::S_BACKSLASH // here
&&
$this->lexer->token['type'] !== EmailLexer::GENERIC
) {
return true;
}
return false;
}
Solution 1:[1]
Issue is that egulias/email-validator
2.1.7 has php 7.4 issues. Simple composer update
fixed it.
Solution 2:[2]
In my case i have just updated code In line 147 of this file vendor\egulias\email-validator\EmailValidator\Parser\Parser.php i have just updated it as
Previous code was if ($previous['type'] === EmailLexer::S_BACKSLASH New code if (isset($previous['type']) && $previous['type'] === EmailLexer::S_BACKSLASH and my problem solved.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | mkrell |
Solution 2 | Aadi Tripathi |