Mailer

Type
Class
Namespace
craft\mail
Inherits
craft\mail\Mailer » yii\symfonymailer\Mailer
Extended by
craft\test\TestMailer
Since
3.0.0

The Mailer component provides APIs for sending email in Craft.

An instance of the Mailer component is globally accessible in Craft via Craft::$app->mailer.

View source (opens new window)

# Public Properties

Property Description
from string (opens new window), array (opens new window), craft\elements\User, craft\elements\User[], null (opens new window) – The default sender’s email address, or their user model(s).
replyTo string (opens new window), array (opens new window), craft\elements\User, craft\elements\User[], null (opens new window) – The default Reply-To email address, or their user model(s).
template string (opens new window), null (opens new window) – The email template that should be used

# from

Type
string (opens new window), array (opens new window), craft\elements\User, craft\elements\User[], null (opens new window)
Default value
null

The default sender’s email address, or their user model(s).

View source (opens new window)

# replyTo

Type
string (opens new window), array (opens new window), craft\elements\User, craft\elements\User[], null (opens new window)
Default value
null
Since
3.4.0

The default Reply-To email address, or their user model(s).

View source (opens new window)

# template

Type
string (opens new window), null (opens new window)
Default value
null

The email template that should be used

View source (opens new window)

# Public Methods

Method Description
composeFromKey() Composes a new email based on a given key.
send()

# composeFromKey()

Composes a new email based on a given key.

Craft has four predefined email keys: account_activation, verify_new_email, forgot_password, and test_email. Plugins can register additional email keys using the registerEmailMessages (opens new window) hook, and by providing the corresponding language strings.

Craft::$app->mailer->composeFromKey('account_activation', [
    'link' => $activationUrl
]);

View source (opens new window)

Arguments

Returns

craft\mail\Message – The new email message

Throws

# send()

View source (opens new window)

Arguments

  • $message

# Events

# EVENT_BEFORE_PREP

Type
yii\mail\MailEvent (opens new window)
Since
3.6.5

The event that is triggered before a message is prepped to be sent.