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那麼多。 –