2
有没有简单的方法来使用CakeEmail“覆盖”电子邮件的目的地?全局覆盖CakeEmail目的地
我有送使用这段代码的电子邮件中的模型方法:
$Email = new CakeEmail();
$Email->config('default');
$sent = $Email->template('new-notification')
->subject('A new notification for you')
->viewVars([
'name' => $foo['User']['name'],
'text' => $foo['Notification']['text'],
)
->emailFormat('html')
->to($foo['User']['email'])
->send();
而且这种配置:
class EmailConfig
{
public $default = array(
'host' => 'smtp.server.com',
'port' => 587,
'username' => '[email protected]',
'password' => 'pwdAsYouKnow',
'from' => array('[email protected]' => 'Company'),
'transport' => 'Smtp'
);
}
正如你所看到的,我发送电子邮件的动态定义用户的电子邮件。
我的目标是当我在本地机器上进行开发时,强制每次致电->send()
强制一个目标,如[email protected]
。
我可以很容易地检测到我是否在开发中,但我不知道如何以CakeEmail的“主”方式强制只发送给定义的帐户,覆盖通话中设置的一个帐户。
我已经尝试设置
'to' => array('[email protected]' => 'Dev'),
内$default
,但没有成功。
我感谢任何帮助,谢谢!
但是,这会迫使我把这个if-block放在每个我称之为' - > to()'的地方不是吗?我正在寻找是否有更广泛的选择,如配置。 也许只有当我封装CakeEmail类...: -/ –
你可以在AppController中添加$到变量或发送电子邮件的助手,我不确定配置我没有使用CakePHP那么多。 –