I am trying to send simple email through mailgun and laravel, but getting a weird error. I am not using queue just sending a simple welcome email on run time.
following is error:
Serialization of 'Closure' is not allowed
Following is mail send code:
$details = array(
'email' => $request->email,
'password' => $request->password,
);
Mail::send('emails.welcome', $details, function ($message) use ($user) {
$message->from('[email protected]', 'Admin');
$message->to($user->email);
});
When I comment above code, everything works fine.
CodePudding user response:
So basically, this is how you trigger the email:
Mail::to("[email protected]")->send(new OrderCreated($order));
OrderCreated class:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class OrderCreated extends Mailable
{
use Queueable, SerializesModels;
public $content;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($content)
{
$this->content = $content;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from(config("mail.mail_from"), "Autokool Service Desk")
->subject("Order Created")
->markdown('emails.order-created')->with('content',$this->content);
}
}
mail.mail_from is the blade view which would be used to create email that will be shown to the user.
CodePudding user response:
I think you got the use of the closure wrong. This should work:
Mail::from('[email protected]', 'Admin')->to($user->email)->send('emails.welcome', $details)