class Mailer implements Mailer, MailQueue

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected array $from

The global from address and name.

protected array $replyTo

The global reply-to address and name.

protected array $returnPath

The global return path address.

protected array $to

The global to address and name.

protected Factory|null $queue

The queue factory implementation.

Methods

static void
macro(string $name, callable|object $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Check if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

__construct(string $name, Factory $views, TransportInterface $transport, Dispatcher|null $events = null)

Create a new Mailer instance.

void
alwaysFrom(string $address, string|null $name = null)

Set the global from address and name.

void
alwaysReplyTo(string $address, string|null $name = null)

Set the global reply-to address and name.

void
alwaysReturnPath(string $address)

Set the global return path address.

void
alwaysTo(string $address, string|null $name = null)

Set the global to address and name.

to(mixed $users, string|null $name = null)

Begin the process of mailing a mailable class instance.

cc(mixed $users, string|null $name = null)

Begin the process of mailing a mailable class instance.

bcc(mixed $users, string|null $name = null)

Begin the process of mailing a mailable class instance.

html(string $html, mixed $callback)

Send a new message with only an HTML part.

raw(string $text, mixed $callback)

Send a new message with only a raw text part.

plain(string $view, array $data, mixed $callback)

Send a new message with only a plain part.

string
render(array|Closure|string $view, array $data = [])

Render the given message as a view.

string
replaceEmbeddedAttachments(string $renderedView, array $attachments)

Replace the embedded image attachments with raw, inline image data for browser rendering.

send(array|Mailable|string $view, array $data = [], Closure|string|null $callback = null)

Send a new message using a view.

sendMailable(Mailable $mailable)

Send the given mailable.

sendNow(array|Mailable|string $mailable, array $data = [], Closure|string|null $callback = null)

Send a new message synchronously using a view.

array
parseView(array|Closure|string $view)

Parse the given view name or array.

void
addContent(Message $message, Closure|Htmlable|string|null $view, Closure|Htmlable|string|null $plain, string|null $raw, array $data = [])

Add the content to a given message.

string
renderView(Closure|Htmlable|string $view, array $data)

Render the given view.

void
setGlobalToAndRemoveCcAndBcc(Message $message)

Set the global "to" address on the given message.

mixed
queue(array|Mailable|string $view, string|null $queue = null)

Queue a new mail message for sending.

mixed
onQueue(string|null $queue, Mailable $view)

Queue a new mail message for sending on the given queue.

mixed
queueOn(string $queue, Mailable $view)

Queue a new mail message for sending on the given queue.

mixed
later(DateInterval|DateTimeInterface|int $delay, array|Mailable|string $view, string|null $queue = null)

Queue a new mail message for sending after (n) seconds.

mixed
laterOn(string $queue, DateInterval|DateTimeInterface|int $delay, Mailable $view)

Queue a new mail message for sending after (n) seconds on the given queue.

createMessage()

Create a new message instance.

SentMessage|null
sendSymfonyMessage(Email $message)

Send a Symfony Email instance.

bool
shouldSendMessage(Email $message, array $data = [])

Determines if the email can be sent.

void
dispatchSentEvent(SentMessage $message, array $data = [])

Dispatch the message sent event.

TransportInterface
getSymfonyTransport()

Get the Symfony Transport instance.

getViewFactory()

Get the view factory instance.

void
setSymfonyTransport(TransportInterface $transport)

Set the Symfony Transport instance.

setQueue(Factory $queue)

Set the queue manager instance.

static void
flushState()

Flush all static state.

Details

in Macroable at line 28
static void macro(string $name, callable|object $macro)

Register a custom macro.

Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.

Parameters

string $name
callable|object $macro

Return Value

void

in Macroable at line 41
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 57
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line 68
static void flushMacros()

Flush the existing macros.

Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.

Return Value

void

in Macroable at line 78
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line 103
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

at line 69
__construct(string $name, Factory $views, TransportInterface $transport, Dispatcher|null $events = null)

Create a new Mailer instance.

Parameters

string $name

the name that is configured for the mailer

Factory $views

the view factory instance

TransportInterface $transport

the Symfony Transport instance

Dispatcher|null $events

the event dispatcher instance

at line 84
void alwaysFrom(string $address, string|null $name = null)

Set the global from address and name.

Boot-only. Mutates the shared Mailer's global from; per-request use races across coroutines and applies the change to every subsequent message.

Parameters

string $address
string|null $name

Return Value

void

at line 96
void alwaysReplyTo(string $address, string|null $name = null)

Set the global reply-to address and name.

Boot-only. Mutates the shared Mailer's global reply-to; per-request use races across coroutines and applies the change to every subsequent message.

Parameters

string $address
string|null $name

Return Value

void

at line 108
void alwaysReturnPath(string $address)

Set the global return path address.

Boot-only. Mutates the shared Mailer's global return path; per-request use races across coroutines and applies the change to every subsequent message.

Parameters

string $address

Return Value

void

at line 120
void alwaysTo(string $address, string|null $name = null)

Set the global to address and name.

Boot-only. Mutates the shared Mailer's global to; once set, Mailer::send() silently redirects every subsequent email across all coroutines to this address. Per-request use is never safe.

Parameters

string $address
string|null $name

Return Value

void

at line 128
PendingMail to(mixed $users, string|null $name = null)

Begin the process of mailing a mailable class instance.

Parameters

mixed $users
string|null $name

Return Value

PendingMail

at line 140
PendingMail cc(mixed $users, string|null $name = null)

Begin the process of mailing a mailable class instance.

Parameters

mixed $users
string|null $name

Return Value

PendingMail

at line 152
PendingMail bcc(mixed $users, string|null $name = null)

Begin the process of mailing a mailable class instance.

Parameters

mixed $users
string|null $name

Return Value

PendingMail

at line 164
SentMessage|null html(string $html, mixed $callback)

Send a new message with only an HTML part.

Parameters

string $html
mixed $callback

Return Value

SentMessage|null

at line 172
SentMessage|null raw(string $text, mixed $callback)

Send a new message with only a raw text part.

Parameters

string $text
mixed $callback

Return Value

SentMessage|null

at line 180
SentMessage|null plain(string $view, array $data, mixed $callback)

Send a new message with only a plain part.

Parameters

string $view
array $data
mixed $callback

Return Value

SentMessage|null

at line 188
string render(array|Closure|string $view, array $data = [])

Render the given message as a view.

Parameters

array|Closure|string $view
array $data

Return Value

string

at line 206
protected string replaceEmbeddedAttachments(string $renderedView, array $attachments)

Replace the embedded image attachments with raw, inline image data for browser rendering.

Parameters

string $renderedView
array $attachments

Return Value

string

at line 230
SentMessage|null send(array|Mailable|string $view, array $data = [], Closure|string|null $callback = null)

Send a new message using a view.

Parameters

array|Mailable|string $view
array $data
Closure|string|null $callback

Return Value

SentMessage|null

at line 284
protected SentMessage|null sendMailable(Mailable $mailable)

Send the given mailable.

Parameters

Mailable $mailable

Return Value

SentMessage|null

at line 299
SentMessage|null sendNow(array|Mailable|string $mailable, array $data = [], Closure|string|null $callback = null)

Send a new message synchronously using a view.

Parameters

array|Mailable|string $mailable
array $data
Closure|string|null $callback

Return Value

SentMessage|null

at line 311
protected array parseView(array|Closure|string $view)

Parse the given view name or array.

Parameters

array|Closure|string $view

Return Value

array

Exceptions

InvalidArgumentException

at line 337
protected void addContent(Message $message, Closure|Htmlable|string|null $view, Closure|Htmlable|string|null $plain, string|null $raw, array $data = [])

Add the content to a given message.

Parameters

Message $message
Closure|Htmlable|string|null $view
Closure|Htmlable|string|null $plain
string|null $raw
array $data

Return Value

void

at line 355
protected string renderView(Closure|Htmlable|string $view, array $data)

Render the given view.

Parameters

Closure|Htmlable|string $view
array $data

Return Value

string

at line 367
protected void setGlobalToAndRemoveCcAndBcc(Message $message)

Set the global "to" address on the given message.

Parameters

Message $message

Return Value

void

at line 382
mixed queue(array|Mailable|string $view, string|null $queue = null)

Queue a new mail message for sending.

Parameters

array|Mailable|string $view
string|null $queue

Return Value

mixed

Exceptions

InvalidArgumentException

at line 398
mixed onQueue(string|null $queue, Mailable $view)

Queue a new mail message for sending on the given queue.

Parameters

string|null $queue
Mailable $view

Return Value

mixed

at line 408
mixed queueOn(string $queue, Mailable $view)

Queue a new mail message for sending on the given queue.

This method didn't match rest of framework's "onQueue" phrasing. Added "onQueue".

Parameters

string $queue
Mailable $view

Return Value

mixed

at line 418
mixed later(DateInterval|DateTimeInterface|int $delay, array|Mailable|string $view, string|null $queue = null)

Queue a new mail message for sending after (n) seconds.

Parameters

DateInterval|DateTimeInterface|int $delay
array|Mailable|string $view
string|null $queue

Return Value

mixed

Exceptions

InvalidArgumentException

at line 433
mixed laterOn(string $queue, DateInterval|DateTimeInterface|int $delay, Mailable $view)

Queue a new mail message for sending after (n) seconds on the given queue.

Parameters

string $queue
DateInterval|DateTimeInterface|int $delay
Mailable $view

Return Value

mixed

at line 441
protected Message createMessage()

Create a new message instance.

Return Value

Message

at line 469
protected SentMessage|null sendSymfonyMessage(Email $message)

Send a Symfony Email instance.

Parameters

Email $message

Return Value

SentMessage|null

at line 480
protected bool shouldSendMessage(Email $message, array $data = [])

Determines if the email can be sent.

Parameters

Email $message
array $data

Return Value

bool

at line 498
protected void dispatchSentEvent(SentMessage $message, array $data = [])

Dispatch the message sent event.

Parameters

SentMessage $message
array $data

Return Value

void

at line 510
TransportInterface getSymfonyTransport()

Get the Symfony Transport instance.

Return Value

TransportInterface

at line 518
Factory getViewFactory()

Get the view factory instance.

Return Value

Factory

at line 530
void setSymfonyTransport(TransportInterface $transport)

Set the Symfony Transport instance.

Boot-only. Replaces the transport on the shared Mailer; per-request use races across coroutines and routes every other coroutine's mail through the swapped transport.

Parameters

TransportInterface $transport

Return Value

void

at line 541
Mailer setQueue(Factory $queue)

Set the queue manager instance.

Boot-only. Replaces the queue factory on the shared Mailer; per-request use races across coroutines.

Parameters

Factory $queue

Return Value

Mailer

at line 551
static void flushState()

Flush all static state.

Return Value

void