PHP Класс yii\mail\BaseMailer

Concrete child classes should may focus on implementing the BaseMailer::sendMessage method.
См. также: BaseMessage
С версии: 2.0
Автор: Paul Klimov ([email protected])
Наследование: extends yii\base\Component, implements yii\mail\MailerInterface, implements yii\base\ViewContextInterface
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$fileTransportCallback a PHP callback that will be called by BaseMailer::send when [[useFileTransport]] is true. The callback should return a file name which will be used to save the email message. If not set, the file name will be generated based on the current timestamp. The signature of the callback is: php function ($mailer, $message)
$fileTransportPath the directory where the email messages are saved when [[useFileTransport]] is true.
$htmlLayout HTML layout view name. This is the layout used to render HTML mail body. The property can take the following values: - a relative view name: a view file relative to [[viewPath]], e.g., 'layouts/html'. - a path alias: an absolute view file path specified as a path alias, e.g., '@app/mail/html'. - a boolean false: the layout is disabled.
$messageClass the default class name of the new message instances created by BaseMailer::createMessage
$messageConfig the configuration that should be applied to any newly created email message instance by BaseMailer::createMessage or BaseMailer::compose. Any valid property defined by MessageInterface can be configured, such as from, to, subject, textBody, htmlBody, etc. For example: php [ 'charset' => 'UTF-8', 'from' => '[email protected]', 'bcc' => '[email protected]', ]
$textLayout text layout view name. This is the layout used to render TEXT mail body. Please refer to [[htmlLayout]] for possible values that this property can take.
$useFileTransport whether to save email messages as files under [[fileTransportPath]] instead of sending them to the actual recipients. This is usually used during development for debugging purpose.

Открытые методы

Метод Описание
afterSend ( yii\mail\MessageInterface $message, boolean $isSuccessful ) This method is invoked right after mail was send.
beforeSend ( yii\mail\MessageInterface $message ) : boolean This method is invoked right before mail send.
compose ( string | array | null $view = null, array $params = [] ) : yii\mail\MessageInterface Creates a new message instance and optionally composes its body content via view rendering.
generateMessageFileName ( ) : string
getView ( ) : View
getViewPath ( ) : string
render ( string $view, array $params = [], string | boolean $layout = false ) : string Renders the specified view with optional parameters and layout.
send ( yii\mail\MessageInterface $message ) : boolean Sends the given email message.
sendMultiple ( array $messages ) : integer Sends multiple messages at once.
setView ( array | View $view )
setViewPath ( string $path )

Защищенные методы

Метод Описание
createMessage ( ) : yii\mail\MessageInterface Creates a new message instance.
createView ( array $config ) : View Creates view instance from given configuration.
saveMessage ( yii\mail\MessageInterface $message ) : boolean Saves the message as a file under [[fileTransportPath]].
sendMessage ( yii\mail\MessageInterface $message ) : boolean Sends the specified message.

Описание методов

afterSend() публичный Метод

You may override this method to do some postprocessing or logging based on mail send status. If you override this method, please make sure you call the parent implementation first.
public afterSend ( yii\mail\MessageInterface $message, boolean $isSuccessful )
$message yii\mail\MessageInterface
$isSuccessful boolean

beforeSend() публичный Метод

You may override this method to do last-minute preparation for the message. If you override this method, please make sure you call the parent implementation first.
public beforeSend ( yii\mail\MessageInterface $message ) : boolean
$message yii\mail\MessageInterface
Результат boolean whether to continue sending an email.

compose() публичный Метод

Creates a new message instance and optionally composes its body content via view rendering.
public compose ( string | array | null $view = null, array $params = [] ) : yii\mail\MessageInterface
$view string | array | null the view to be used for rendering the message body. This can be: - a string, which represents the view name or path alias for rendering the HTML body of the email. In this case, the text body will be generated by applying `strip_tags()` to the HTML body. - an array with 'html' and/or 'text' elements. The 'html' element refers to the view name or path alias for rendering the HTML body, while 'text' element is for rendering the text body. For example, `['html' => 'contact-html', 'text' => 'contact-text']`. - null, meaning the message instance will be returned without body content. The view to be rendered can be specified in one of the following formats: - path alias (e.g. "@app/mail/contact"); - a relative view name (e.g. "contact") located under [[viewPath]].
$params array the parameters (name-value pairs) that will be extracted and made available in the view file.
Результат yii\mail\MessageInterface message instance.

createMessage() защищенный Метод

The newly created instance will be initialized with the configuration specified by [[messageConfig]]. If the configuration does not specify a 'class', the [[messageClass]] will be used as the class of the new message instance.
protected createMessage ( ) : yii\mail\MessageInterface
Результат yii\mail\MessageInterface message instance.

createView() защищенный Метод

Creates view instance from given configuration.
protected createView ( array $config ) : View
$config array view configuration.
Результат yii\web\View view instance.

generateMessageFileName() публичный Метод

public generateMessageFileName ( ) : string
Результат string the file name for saving the message when [[useFileTransport]] is true.

getView() публичный Метод

public getView ( ) : View
Результат yii\web\View view instance.

getViewPath() публичный Метод

public getViewPath ( ) : string
Результат string the directory that contains the view files for composing mail messages Defaults to '@app/mail'.

render() публичный Метод

The view will be rendered using the [[view]] component.
public render ( string $view, array $params = [], string | boolean $layout = false ) : string
$view string the view name or the path alias of the view file.
$params array the parameters (name-value pairs) that will be extracted and made available in the view file.
$layout string | boolean layout view name or path alias. If false, no layout will be applied.
Результат string the rendering result.

saveMessage() защищенный Метод

Saves the message as a file under [[fileTransportPath]].
protected saveMessage ( yii\mail\MessageInterface $message ) : boolean
$message yii\mail\MessageInterface
Результат boolean whether the message is saved successfully

send() публичный Метод

This method will log a message about the email being sent. If [[useFileTransport]] is true, it will save the email as a file under [[fileTransportPath]]. Otherwise, it will call BaseMailer::sendMessage to send the email to its recipient(s). Child classes should implement BaseMailer::sendMessage with the actual email sending logic.
public send ( yii\mail\MessageInterface $message ) : boolean
$message yii\mail\MessageInterface email message instance to be sent
Результат boolean whether the message has been sent successfully

sendMessage() абстрактный защищенный Метод

This method should be implemented by child classes with the actual email sending logic.
abstract protected sendMessage ( yii\mail\MessageInterface $message ) : boolean
$message yii\mail\MessageInterface the message to be sent
Результат boolean whether the message is sent successfully

sendMultiple() публичный Метод

The default implementation simply calls BaseMailer::send multiple times. Child classes may override this method to implement more efficient way of sending multiple messages.
public sendMultiple ( array $messages ) : integer
$messages array list of email messages, which should be sent.
Результат integer number of messages that are successfully sent.

setView() публичный Метод

public setView ( array | View $view )
$view array | yii\web\View view instance or its array configuration that will be used to render message bodies.

setViewPath() публичный Метод

public setViewPath ( string $path )
$path string the directory that contains the view files for composing mail messages This can be specified as an absolute path or a path alias.

Описание свойств

$fileTransportCallback публичное свойство

a PHP callback that will be called by BaseMailer::send when [[useFileTransport]] is true. The callback should return a file name which will be used to save the email message. If not set, the file name will be generated based on the current timestamp. The signature of the callback is: php function ($mailer, $message)
public $fileTransportCallback

$fileTransportPath публичное свойство

the directory where the email messages are saved when [[useFileTransport]] is true.
public $fileTransportPath

$htmlLayout публичное свойство

HTML layout view name. This is the layout used to render HTML mail body. The property can take the following values: - a relative view name: a view file relative to [[viewPath]], e.g., 'layouts/html'. - a path alias: an absolute view file path specified as a path alias, e.g., '@app/mail/html'. - a boolean false: the layout is disabled.
public $htmlLayout

$messageClass публичное свойство

the default class name of the new message instances created by BaseMailer::createMessage
public $messageClass

$messageConfig публичное свойство

the configuration that should be applied to any newly created email message instance by BaseMailer::createMessage or BaseMailer::compose. Any valid property defined by MessageInterface can be configured, such as from, to, subject, textBody, htmlBody, etc. For example: php [ 'charset' => 'UTF-8', 'from' => '[email protected]', 'bcc' => '[email protected]', ]
public $messageConfig

$textLayout публичное свойство

text layout view name. This is the layout used to render TEXT mail body. Please refer to [[htmlLayout]] for possible values that this property can take.
public $textLayout

$useFileTransport публичное свойство

whether to save email messages as files under [[fileTransportPath]] instead of sending them to the actual recipients. This is usually used during development for debugging purpose.
См. также: fileTransportPath
public $useFileTransport