System\Classes\MailManager
Overview
MailManager manages Mail sending functions
Protected Properties
protected array $templateCache
A cache of customized mail templates.
protected array $registeredTemplates
List of registered templates in the system
protected array $registeredPartials
List of registered partials in the system
protected array $registeredLayouts
List of registered layouts in the system
protected bool $isHtmlRenderMode
Internal marker for rendering mode
protected string|null $renderLocale
renderLocale is the locale used for the current render.
Public Methods
public addContentFromEvent()
public addContentFromEvent(
$message,
$view = null,
$plain = null,
$raw = null,
$data = []
): void
addContentFromEvent handles adding content from the mailer.beforeAddContent event
public addContentToMailer()
public addContentToMailer(
Illuminate\Mail\Message $message,
string $code,
array $data,
bool $plainOnly = false
): bool
addContentToMailer function hijacks the addContent method of the
October\Rain\Mail\Mailer class, using the mailer.beforeAddContent event.
public addRawContentToMailer()
public addRawContentToMailer($message, $content, $data): bool
addRawContentToMailer is the same as addContentToMailer except with raw content
public findLocalizedView()
public findLocalizedView(
string $view,
string|null $locale = null
): string|null
findLocalizedView returns a localized view name resolved from a locale subdirectory (mail.welcome gives mail.fr.welcome), or null when none exists.
public getViewPathForTemplate()
public getViewPathForTemplate($code): string|null
getViewPathForTemplate returns a view path for a registered template
public static instance()
public static instance(): static
instance creates a new instance of this singleton
public listRegisteredLayouts()
public listRegisteredLayouts(): array
listRegisteredLayouts returns a list of the registered layouts.
public listRegisteredPartials()
public listRegisteredPartials(): array
listRegisteredPartials returns a list of the registered partials.
public listRegisteredTemplates()
public listRegisteredTemplates(): array
listRegisteredTemplates returns a list of the registered templates.
public loadRegisteredTemplates()
public loadRegisteredTemplates(): void
loadRegisteredTemplates loads registered mail templates from modules and plugins
public static registerCallback()
public static registerCallback(callable $callback): void
registerCallback registers a callback function that defines mail templates. The callback function should register templates by calling the manager's registerMailTemplates() function. Thi instance is passed to the callback function as an argument. Usage:
MailManager::registerCallback(function ($manager) {
$manager->registerMailTemplates([...]);
});
public registerMailLayouts()
public registerMailLayouts($definitions): void
registerMailLayouts registers mail views and manageable layouts.
public registerMailPartials()
public registerMailPartials($definitions): void
registerMailPartials registers mail views and manageable layouts.
public registerMailTemplates()
public registerMailTemplates($definitions): void
registerMailTemplates registers mail views and manageable templates.
public render()
public render(string $content, array $data = []): string
render the Markdown template into HTML
public renderPartial()
public renderPartial($code, $params = []): void
public renderTemplate()
public renderTemplate($template, $data = []): void
public renderText()
public renderText($content $content, array $data = []): string
renderText renders the Markdown template into text.
public renderTextTemplate()
public renderTextTemplate($template, $data = []): void
public withLocale()
public withLocale(string $locale, Closure(): $callback): TReturn
Run the callback with the given locale.
Protected Methods
protected addContentToMailerInternal()
protected addContentToMailerInternal(
Illuminate\Mail\Message $message,
MailTemplate $template,
array $data,
bool $plainOnly = false
): void
addContentToMailerInternal is an internal method used to share logic
between addRawContentToMailer and addContentToMailer
protected applyTranslateContext()
protected applyTranslateContext(
mixed $model,
string|null $locale
): void
applyTranslateContext sets the locale context on a translatable model using the locale key chain, always resetting the context to avoid reusing a stale locale.
protected getMailLocale()
protected getMailLocale(array $data): string|null
getMailLocale returns the target locale for a mail message, or null when translation is disabled.
protected localizeMailPartial()
protected localizeMailPartial(
System\Models\MailPartial $partial,
string $code,
string|null $locale
): void
localizeMailPartial applies a locale to a resolved partial, mirroring the template rules where stored translations take precedence over view files.
protected localizeMailTemplate()
protected localizeMailTemplate(
System\Models\MailTemplate|null $template,
string $code,
string|null $locale
): void
localizeMailTemplate applies a locale to a resolved template, refilling from a localized view file when available and applying stored translations, which take precedence over view files.
protected makeLocalizedViewName()
protected makeLocalizedViewName($view, $locale): string
makeLocalizedViewName inserts a locale segment before the final view name, preserving any view namespace.
protected parseTwig()
protected parseTwig($contents, $vars = []): void
parseTwig parses Twig using the mailer environment