簡體   English   中英

我如何在Cakephp中發送電子郵件-從本地主機到gmail帳戶

[英]how can i send email in cakephp - to gmail account from localhost

我在這個問題上是乞gg,我發現了這個問題...我想將電子郵件從我的本地主機發送到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()**

請幫助!非常感謝!!!

    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;
            }         
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM