我正在尝试发送一封带有cakephp的电子邮件。 我的设置代码如下。如果我为gmail或快速切换配置,或将viewVars添加到其他电子邮件设置并不重要 - 我收到此错误:
Call to a member function viewVars() on array
如果我从新的CakeEmail()块中删除了viewVars行 - 它给了我
Call to a member function send() on array
这让我觉得我的设置在某处出现了问题?
我在控制器中设置了这样的电子邮件:
$email = new CakeEmail();
$email->template('remember_password', 'default')
->config('default')
->emailFormat('html')
->subject(__('Remember password - ' . Configure::read('Application.name')))
->to($user['User']['email'])
->from(Configure::read('Application.from_email'))
->viewVars(array('hash' => $hash))
->send();
设置如下:
class EmailConfig {
public $default = array(
'transport' => 'Mail',
'from' => 'myemail@email.com',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
public $smtp = array(
'transport' => 'Smtp',
'from' => array('myemail@email.com' => 'My Site'),
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null,
'log' => false,
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
public $gmail = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'myemail@email.com',
'password' => 'password',
'transport' => 'Smtp',
);
public $fast = array(
'from' => 'myemail@email.com',
'sender' => null,
'to' => null,
'cc' => null,
'bcc' => null,
'replyTo' => null,
'readReceipt' => null,
'returnPath' => null,
'messageId' => true,
'subject' => null,
'message' => null,
'headers' => null,
'viewRender' => null,
'template' => false,
'layout' => false,
'viewVars' => null,
'attachments' => null,
'emailFormat' => null,
'transport' => 'Smtp',
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null,
'log' => true,
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
答案 0 :(得分:4)
Application.from_email
不存在或者是null
,导致CakeEmail::from()
接收null
作为参数,导致它充当getter,即它将返回当前from
值,这是一个数组,因此是错误。