Commit ccd16e18 by Carsten Brandt

added mailer to the message when using compose

more expected behavior when chaining methods using Mailser::compose() fixes #2723
parent 53e65b23
......@@ -188,7 +188,6 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
$message->setTextBody(strip_tags($html));
}
}
return $message;
}
......@@ -205,7 +204,7 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
if (!array_key_exists('class', $config)) {
$config['class'] = $this->messageClass;
}
$config['mailer'] = $this;
return Yii::createObject($config);
}
......
......@@ -24,14 +24,26 @@ use Yii;
abstract class BaseMessage extends Object implements MessageInterface
{
/**
* @inheritdoc
* @var MailerInterface the mailer instance that created this message.
* For independently created messages this is `null`.
*/
public $mailer;
/**
* Sends this email message.
* @param MailerInterface $mailer the mailer that should be used to send this message.
* If no mailer is given it will first check if [[mailer]] is set and if not,
* the "mail" application component will be used instead.
* @return boolean whether this message is sent successfully.
*/
public function send(MailerInterface $mailer = null)
{
if ($mailer === null) {
if ($mailer === null && $this->mailer === null) {
$mailer = Yii::$app->getMail();
} elseif ($mailer === null) {
$mailer = $this->mailer;
}
return $mailer->send($this);
}
......@@ -47,7 +59,6 @@ abstract class BaseMessage extends Object implements MessageInterface
return $this->toString();
} catch (\Exception $e) {
trigger_error($e->getMessage() . "\n\n" . $e->getTraceAsString());
return '';
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment