So I'm trying to send an html email in Laravel 5.6 and am running into some fun issues.
For one, the documentation is pretty terrible when it comes to customizing the HTML content, or even using the default HTML layout.
https://laravel.com/docs/5.6/mail#writing-mailables
There is a section for "Configuring the View" where it tells you to just do something like the following.
return $this->view('emails.orders.shipped');
Cool, I'm doing that. In my blade file I have just
Here is a test message.
And it sends just fine. But what doesn't make any sense is that the page also says you can run the following artisan command to generate the default email template.
php artisan vendor:publish --tag=laravel-mail
It says "The mail directory will contain a html and a markdown directory, each containing their respective representations of every available component. The components in the html directory are used to generate the HTML version of your email."
The documentation also goes into depth about how to customize and use these markdown templates. You just call @component('mail::message')
at the top of the markdown blade file... but I do not want markdown. I just want the regular HTML email.
@component('mail::message')
doesn't work when using ->view()
only when using ->markdown()
. I also can't just do the following.
@extends('vendor.mail.html.layout')
Test message
As it tells me slot is an undefined variable in the error log.
Not sure why, the layout.blade.php file in the /vendor/mail/html/ directory contains the following...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<style>
@media only screen and (max-width: 600px) {
.inner-body {
width: 100% !important;
}
.footer {
width: 100% !important;
}
}
@media only screen and (max-width: 500px) {
.button {
width: 100% !important;
}
}
</style>
<table class="wrapper" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<table class="content" width="100%" cellpadding="0" cellspacing="0">
{{ $header ?? '' }}
<!-- Email Body -->
<tr>
<td class="body" width="100%" cellpadding="0" cellspacing="0">
<table class="inner-body" align="center" width="570" cellpadding="0" cellspacing="0">
<!-- Body content -->
<tr>
<td class="content-cell">
{{ Illuminate\Mail\Markdown::parse($slot) }}
{{ $subcopy ?? '' }}
</td>
</tr>
</table>
</td>
</tr>
{{ $footer ?? '' }}
</table>
</td>
</tr>
</table>
</body>
</html>
Not sure why it's calling Markdown::parse($slot)
in the html version of the email.
How do I go about extending this view in an html email? Was hoping to at least get the default html template without having to build my own...
$slot
is only defined when you use@component
so you might try@component('vendor.mail.html.layout')
instead of@extends
. The relevant documentation is in blade templates – apokryfosvendor.mail.html.message
it sends, but none of my component in @slot('header') @endslot shows up anywhere – Octoxan