A Mailable class
A Mailable class holds everything about one message: who it is for, what it says, and which view renders it. Each mail type gets its own class, so order mail and welcome mail never mix.
Generate the class with artisan and pass data through the constructor, the same way controllers receive models.
php artisan make:mail OrderShipped
INFO Mail [app/Mail/OrderShipped.php] created successfully.
Build the message
The classic build method sets the subject and picks the view in one chain. Keep the method small: subject first, then the view name.
Put the HTML itself in the Blade view, not in the class, so designers edit markup without touching PHP.
public function build() { return $this->subject("Your order shipped")->view("emails.shipped"); }
Send it
Send with the Mail facade by naming one receiver and handing over a Mailable instance. Load the order first, then send exactly one message per receiver.
Heavy apps send mail in the background, so read the queues lesson before wiring large volumes.
$order = Order::find(7); Mail::to("buyer@example.com")->send(new OrderShipped($order));
Log driver locally
Local apps should never send real mail while testing. The log driver writes every message to the log file instead of delivering it.
Switch the mailer in the env file and inspect the log after each send to confirm subject and content.
MAIL_MAILER=log MAIL_FROM_ADDRESS="shop@example.com"
Next: Cache
Article author: Arthur Isaev