【发布时间】:2014-05-13 22:23:23
【问题描述】:
我是初学者,我发现了这个问题...我想从我的本地主机发送电子邮件到一个 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, line 124]
错误:在非对象上调用成员函数 send() **
请帮忙!!!非常感谢!!!
【问题讨论】:
-
在我看来,您正在将 CakeEmail 类实例化为变量
$Email,然后您将其称为$this->Email->...-$this指的是当前类(您的控制器),所以在你的情况下你应该使用$Email->to等而不是使用$this -
是的,它可以工作,但现在我有这个错误:未指定来自。错误:发生内部错误。
-
我已经找到了解决方案,谢谢scrowler!!我将我的解决方案基于您的回答!!...我正在做“$this->Email->from = 'xxxx@gmail.com';”,但我发现是这样的:“$Email->from( array('jmickyramirez@gmail.com' => 'My Site'));",最后我必须删除'='并输入'(我的代码)'...非常感谢scrowler!!..跨度>