【问题标题】:getting error Could not send email in cakephp收到错误无法在cakephp中发送电子邮件
【发布时间】:2013-09-12 10:53:18
【问题描述】:

我一直在尝试通过 Gmail 在 xampp 上使用 Pear 发送电子邮件,在花了几个小时进行设置并找出我遇到的所有错误之后,我以为我已经很接近了,直到我开始收到这个错误: 控制器动作

 public function automail() {
    App::uses('CakeEmail', 'Network/Email');
    $ret_msg = null;
    try {

        $is_call_email = true;
        $subject = "case detail";
        $comment = "Ready to Review";
        $email_to = "exmaple@gmail.com";

        if ($is_call_email == true) {
            $email_to = str_replace(' ', '', $email_to);
            $email_addresses = preg_split('/[;,]/', $email_to);

            $this->log($is_call_email,'bool');
            $email = new CakeEmail();                         
            $email->from(array($this->Session->read('Auth.User.email') => $this->Session->read('Auth.User.name')))                
                    ->to($email_addresses)                
                      ->subject($subject)                        
                        ->send($comment);
            $this->log($subject,'subject');
        } 
    } catch (Exception $ex) {
        $ret_msg = $ex->getMessage();
        $this->log($ex->getLine(), 'emailError');
    }

    $this->log('Return msg is  = ' . $ret_msg, 'shared');
    return;

在 email.php 中

<?php 
class EmailConfig {

    public $default = array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => 465,
        'username' => 'example@gmail.com', //example@gmail.com
        'password' => 'secret',
        'transport' => 'Smtp',
        'from' => array('exampe@gmail.com' => 'Nam Email'),
        'log' => true
    );

}

from 和 to 都是相同的电子邮件地址,因为我被发送到我的帐户中进行测试... 请帮助我或任何关于如何使用 cakephp 发送电子邮件的建议......

【问题讨论】:

    标签: php email cakephp smtp cakephp-2.0


    【解决方案1】:

    您需要指定$email-&gt;config。喜欢:

    $email->config('default')
          ->from(array($this->Session->read('Auth.User.email') => $this->Session->read('Auth.User.name')))                
          ->to($email_addresses)                
          ->subject($subject)                        
          ->send($comment);
    

    【讨论】:

      猜你喜欢
      • 2013-07-14
      • 2018-07-16
      • 2013-04-08
      • 2013-04-01
      • 2012-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-06
      相关资源
      最近更新 更多