I think you got the variable order wrong, try
return new EmailVerification($maildata, $verifyUrl, $notifiable);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello :)
I have a problem with passing a Variable to Markdown from Notification through Mailable via AppServiceProvider. I think i overcomplicated it.
Im getting the error Undefined variable: maildata (View: message.blade.php)
I have to pass the $maildata (array) to the markdown.
I Override the VerifyEmail::toMailUsing Method in AppServiceProvider.php boot method (dont know if its needed)
AppServiceProvider.php
// Override the email notification for verifying email
VerifyEmail::toMailUsing(function ($notifiable){
$verifyUrl = URL::temporarySignedRoute(
'verification.verify',
Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)),
['id' => $notifiable->getKey()]
);
$maildata = [
'mainTitle' => 'TEST'
];
return new EmailVerification($verifyUrl, $notifiable, $maildata);
});
EmailVerification.php Mailable
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class EmailVerification extends Mailable
{
use Queueable, SerializesModels;
public $verifyUrl;
protected $user;
public $maildata;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($maildata, $url, $user)
{
$this->maildata = $maildata;
$this->verifyUrl = $url;
$this->user = $user;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->markdown( 'mail.emailVerification', compact('maildata') );
}
}
My message.blade.php
@component('mail::layout')
{{-- Header --}}
@slot('header')
@component('mail::header', ['maildata' => $maildata])
@endcomponent
@endslot
{{-- Body --}}
{{ $slot }}
{{-- Subcopy --}}
@isset($subcopy)
@slot('subcopy')
@component('mail::subcopy')
{{ $subcopy }}
@endcomponent
@endslot
@endisset
{{-- Footer --}}
@slot('footer')
@component('mail::footer')
@endcomponent
@endslot
@endcomponent
What am I doing wrong? I tried some different approaches witch compact, a new mailable, new notification. Nothing worked. I also checked the GitHub Issue https://github.com/laravel/framework/issues/18597
Nothing worked for me.
If i remove the maildata in the component the email sending works, just without the variable data :(
thx hope someone has an approach for me.
Please or to participate in this conversation.