我在这方面很好,我发现这个问题...我想从我的localhost发送电子邮件到一个Gmail帐户(这最后可以更改为一个hotmail),但首先我要证明一个gmail帐户。 我配置了我的email.php,看起来像这样:
public $gmail = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'xxxxx@gmail.com',
'password' => 'xxxx',
'transport' => 'Smtp'
);
在我的控制器中我有这个
public function compras()
{
$Email = new CakeEmail();
$Email->config('gmail');
$this->loadModel('Soya');
$this->paginate = array(
'conditions' => array('Grupo.categoria' => 'Soya','Grupo.subcategoria' => 'Productor de Oleaginosas'),
'limit' => 25
);
$this->set('soyas', $this->paginate('Soya'));
$this->Email->to = 'xxxx@gmail.com';
$this->Email->subject = 'Include your subject';
$this->Email->from = 'xxxx@gmail.com';
//$this->Email->template = 'template'; // file name template.ctp will be included in /views/elements/email/text/template.ctp
$this->Email->delivery = 'smtp';
if ($this->Email->send()
) {
return true;
} else {
echo $this->Email->smtpError;
}
}
但是当我编译时出现错误
**间接修改重载属性SoyasController :: $ Email无效[APP / Controller / SoyasController.php,第124行]
错误:在非对象**
上调用成员函数send()请帮助!!!非常感谢!!!
答案 0 :(得分:0)
public function compras()
{
$Email = new CakeEmail();
$Email->config('gmail');
$this->loadModel('Soya');
$this->paginate = array(
'conditions' => array('Grupo.categoria' => 'Soya','Grupo.subcategoria' => 'Productor de Oleaginosas'),
'limit' => 25
);
$this->set(array('soyas', $this->paginate('Soya')));
$Email->to('xxxx@gmail.com');
$Email->subject('Include your subject');
$Email->from('xxxx@gmail.com');
if ($Email->send())
{
return true;
} else {
echo $this->Email->smtpError;
}
}