配置并重写模块中邮件文件中的$viewPath属性。
例子:
public $viewPath = '@myvendor/mymodule/mail';
首先,创建新的 html 和文本文件。创建这两个文件。
创建这两个文件。
- 邮件/新HTML
邮件/trxt/NewTEXT
$mailer = Yii::$app->mailer;
$mailer->viewPath = $this->viewPath;
$mailer->getView()->theme = Yii::$app->view->theme;
return $mailer->compose(['html' => $view, 'text' => 'text/' . $view], $params)
->setTo($to)
->setFrom($this->sender)
->setSubject($subject)
->send();
如果您只想更改一个路径:在代码之前使用:
Yii :: $ app-> mailer-> viewPath = '@ myvendor / newPath';
Yii::$app->mailer->compose([ #code...
如果是 VIEW 文件:只需要更改 HTML 和 TEXT 文件的名称,(两者)
更新:
它可以被覆盖或通过一个组件和...
//new file: path\widgets\Mailer.php
namespace path\widgets;
use yourpath\Mailer as DefaultMailer; //path:mymodule/mail
class Mailer extends DefaultMailer{
public $viewPath = '@myvendor/mymodule/mail';
public function changeviewPath($_path){
$this->viewPath; = $_path;
}
}
// 用来。变化
use path\widgets\Maile; // New path
// Use before the usual code
$mailer->changeviewPath('newpath\mail');
更改组件中文件的地址。根据您的电子邮件模块,它会有所不同
例子:
'modules' => [
'myMudul' => [
'class' => 'PathModule\Module',
'mailer' => [
#code ..
],
],
...