MailChannel
final class MailChannel implements Channel
Notification channel that sends email via the framework MailerService and/or AbstractMailer-based custom mailers.
Supported payload shapes (returned by Notification::toMail()):
1) Template mode (MailerService::sendTemplate) [ // 'to' => 'user@example.com', // optional; auto-routes from notifiable if omitted 'subject' => 'Subject', 'template' => 'welcome', 'data' => ['user' => $user], 'layout' => 'default', // optional 'attachments' => [...], // optional (use Attachments::content/path helpers) 'layoutPath' => null, // optional 'templatePath'=> null, // optional 'styles' => 'default', // optional 'stylesPath' => null, // optional ]
2) Raw HTML (MailerService::send / sendWithText) [ // 'to' => 'user@example.com', // optional; auto-route 'subject' => 'Subject', 'html' => '
Hello
', 'text' => 'Hello', // optional -> triggers sendWithText() 'template' => 'welcome', // optional: used only for logging 'attachments' => [...], // optional ]3) Custom mailer (AbstractMailer subclass) [ 'mailer' => \Core\Lib\Mail\WelcomeMailer::class, // The mailer can implement a static sendTo(\App\Models\Users $user): bool // If not, we construct it and call buildAndSend(...) with optional overrides: 'layout' => null, 'attachments' => [], 'layoutPath' => null, 'templatePath'=> null, 'styles' => null, 'stylesPath' => null, ]
Methods
Constructor for MailChannel.
Determines if mail will be using a template.
Short channel name used in Notification::via().
Setups notification using buildAndSend
Setups notification with html and with text optional.
Setups notification with mail template.
Ensure the notifiable is the expected user type for AbstractMailer.
Resolve recipient email from the notifiable.
Deliver the notification for this channel.
Sends notification through send function of MailerService or if text body exists it uses sendWithText.
Handle AbstractMailer subclasses.
Details
at line 64
__construct(MailerService|null $service = null)
Constructor for MailChannel.
at line 74
private bool
isTemplate(array $payload)
Determines if mail will be using a template.
at line 83
static string
name()
Short channel name used in Notification::via().
at line 94
private bool
notifyWithBuildAndSend(AbstractMailer $mailer, array $payload)
Setups notification using buildAndSend
at line 113
private void
notifyWithHTML(mixed $notification, array $payload, string $subject, string $to)
Setups notification with html and with text optional.
at line 139
private void
notifyWithTemplate(mixed $notification, array $payload, string $subject, string $to)
Setups notification with mail template.
at line 169
static private object
requireUser(object $notifiable)
Ensure the notifiable is the expected user type for AbstractMailer.
at line 184
private string
route(object $notifiable)
Resolve recipient email from the notifiable.
at line 198
void
send(object $notifiable, Notification $notification, mixed $payload)
Deliver the notification for this channel.
Implementations SHOULD be idempotent when possible, or document non-idempotent behavior. If delivery fails, throw an exception to allow the caller (or a queue worker) to handle retries.
at line 257
private bool
sendWithHTML(string $to, string $subject, string $html, string|null $text = null, string|null $template = null, array $attachments = [])
Sends notification through send function of MailerService or if text body exists it uses sendWithText.
at line 276
private void
sendWithCustomMailer(object $notifiable, array $payload)
Handle AbstractMailer subclasses.