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 vendoreguliasemail-validatorEmailValidatorParserParser.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 AppMail;
use IlluminateBusQueueable;
use IlluminateMailMailable;
use IlluminateQueueSerializesModels;
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 vendoreguliasemail-validatorEmailValidatorParserParser.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;
}
2
Answers
Issue is that
egulias/email-validator
2.1.7 has php 7.4 issues. Simplecomposer update
fixed it.In my case i have just updated code In line 147 of this file vendoreguliasemail-validatorEmailValidatorParserParser.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.