Apply
public function apply(Mail $mail) : void
Fires during the application of the rules defined by an action.
Description
Applies the changes defined by the conditional text to a mail instance before sending the notification.
The actions of a conditional text are applied only in case all the assigned filters (if any) are eligible.
In case the class extends the ConditionalTextActionAware
abstraction, it is possible to use the code below to access the configuration of the action.
$this->options->get('param', false);
Where the first argument is the name of the setting defined by the getForm()
method and the second one is the default value to use in case of no stored setting.
Parameters
-
(Mail) The mail instance where the changes can be applied. For further details about the methods supported by this object, you can take a look at the "Before Send" article under the See Also section.
Return Value
None.
Example
The example below explains how to implement an action that changes sender e-mail address and the reply-to. This action could be used in combination with the native Room filter in order to use a different sender depending on the selected room for the reservation to notify.
/**
* @inheritDoc
*
* IMPORTANT: you first need to load the E4J\VikRestaurants\Mail\Mail object accordingly
*/
public function apply(Mail $mail)
{
// get sender e-mail address
$senderMail = $this->options->get('sendermail');
// get sender name
$senderName = $this->options->get('sendername');
if ($senderMail) {
// overwrite the sender with the provided one
$mail->setSender($senderMail, $senderName);
}
// get reply-to e-mail address
$replyto = $this->options->get('replyto');
if ($replyto) {
// overwrite the reply-to address with the provided one
$mail->setReplyTo($replyto);
}
}