如何从本地主机向gmail帐户发送cakephp格式的电子邮件
我是begginer,我发现了这个问题…我想从本地主机向gmail帐户发送电子邮件(最后一个可以更改为hotmail),但首先我想证明我是gmail帐户。 我已经配置了我的email.php,看起来是这样的:如何从本地主机向gmail帐户发送cakephp格式的电子邮件,php,email,cakephp,Php,Email,Cakephp,我是begginer,我发现了这个问题…我想从本地主机向gmail帐户发送电子邮件(最后一个可以更改为hotmail),但首先我想证明我是gmail帐户。 我已经配置了我的email.php,看起来是这样的: public $gmail = array( 'host' => 'ssl://smtp.gmail.com', 'port' => 465, 'username' => 'xxxxx@gmail.com',
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()**
请帮忙!!!非常感谢 在我看来,您正在将CakeEmail类实例化为变量
$Email
,然后进一步将其引用为$this->Email->…
-$this
引用当前类(您的控制器),因此,在您的情况下,您应该使用$Email->to
等,而不要使用$this
是的,它可以工作,但现在我有一个错误:From未指定。错误:发生内部错误。我已找到解决方案,谢谢scrowler!!我是根据你的答案来解决的!!。。。我在做“$this->Email->from=”xxxx@gmail.com“;”,但我发现它是这样的:“$Email->from(array(“)jmickyramirez@gmail.com“=>‘我的网站’);”,最后,我必须删除“=”并放入(我的代码)…非常感谢scrowler!!。。
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;
}
}