yii\mail\BaseMailer::saveMessage PHP Method

saveMessage() protected method

Saves the message as a file under [[fileTransportPath]].
protected saveMessage ( yii\mail\MessageInterface $message ) : boolean
$message yii\mail\MessageInterface
return boolean whether the message is saved successfully
    protected function saveMessage($message)
    {
        $path = Yii::getAlias($this->fileTransportPath);
        if (!is_dir($path)) {
            mkdir($path, 0777, true);
        }
        if ($this->fileTransportCallback !== null) {
            $file = $path . '/' . call_user_func($this->fileTransportCallback, $this, $message);
        } else {
            $file = $path . '/' . $this->generateMessageFileName();
        }
        file_put_contents($file, $message->toString());
        return true;
    }

Usage Example

Example #1
0
 /**
  * @inheritdoc
  */
 protected function saveMessage($message)
 {
     //we have to generate message first - or [[toString()]] returns empty value
     $this->adapter->preSend();
     return parent::saveMessage($message);
 }