【问题标题】:Codeigniter controller showing errorCodeigniter 控制器显示错误
【发布时间】:2016-10-03 09:51:09
【问题描述】:

您好,在从数据库获取数据后,我正在使用 codeigniter 控制器发送电子邮件。但问题是当电子邮件到达$this->email->initialize($config); 时,在调试时它会因错误而崩溃

Severity: Notice

Message: Undefined property : Invoice::$email

Line Number: 563

一切看起来都很好,我通常在很多地方使用这个电子邮件功能。但我无法弄清楚错误。 这是控制器中的代码。

public function sendReminderForUnpaidInvoice() {
        //fetch tha data from the database 
        $this->load->model('invoice_page');
        $foo = $this->invoice_page->get();
        $result = json_decode(json_encode($foo), true);
        foreach ($foo as $result){

            $this->load->library('../controllers/payment');
            $resultMangoPay = $this->payment->getMangopayPayinForTheInvoiceMail($result->rf_reference);
            $totalAmount = ($result->gross_amount) + ($result->type_related_amount) ;
            $this->load->library('email');
            $config['protocol'] = 'smtp';

            $config['smtp_host'] = 'ssl://smtp.gmail.com';

            $config['smtp_port']    = '465';

            $config['smtp_timeout'] = '7';

            $config['smtp_user']    = 'support@aurorax.co';

            $config['smtp_pass']    = '#########';

            $config['charset']    = 'utf-8';

            $config['newline']    = "\r\n";

            $config['mailtype'] = 'text'; // or html

            $config['validation'] = TRUE; // bool whether to validate email or not      

            $this->email->initialize($config); // line 563

            $this->email->from('support@aurorax.co', 'aurora exchange');
            $this->email->to($result->Email);
            $this->email->subject('Repayment invoice');
            $this->email->message(
            'Hello '.$result->Fullname.'.'."\n"
            .'Here is a invoice for the next upcoming payment. '."\n"."\n"
            .'Payment should be done by bank transfer to the information provided below'."\n"
            .'Name :'.$resultMangoPay['OwnerName']
            .'IBAN :'.$resultMangoPay['IBAN']    
                    );  
            $returnvalue = $this->email->send();


            if(!$returnvalue) {
              return false;
            } else {  

               // will do something here later
            }
            $this->email->clear(TRUE);   
        }
    }

【问题讨论】:

  • 你在哪里使用$email
  • @OwaisArain 不,这就是问题所在
  • Line Number: 563在哪里
  • @devpro $this->email->initialize($config); // 第 563 行
  • @OwaisArain 我在很多控制器中都使用这种格式,并且它们都可以工作,这个突然说我正在使用 $email,但我显然不是。

标签: php codeigniter email


【解决方案1】:

您在加载控制器后无法加载 codeigniter 库或模型,它会破坏这种方式,如果您先加载电子邮件库和模型,然后加载 payment 控制器,它应该可以正常工作.

【讨论】:

    【解决方案2】:

    尝试使用数组初始化库。

    $config = array(
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.gmail.com',
        'smtp_port' => 465,
        'smtp_timeout' => '7',
        'smtp_user' => 'support@aurorax.co',
        'smtp_pass' => '#########',
        'charset'   => 'utf-8',
        'newline'   => "\r\n",
        'mailtype'  => 'text',
        'validation' => TRUE
    );
    
    $this->load->library('email', $config);
    

    【讨论】:

    • 现在在这一行给我同样的错误$this->email->from('support@aurorax.co', 'aurora exchange');
    猜你喜欢
    • 1970-01-01
    • 2015-01-20
    • 2016-11-30
    • 1970-01-01
    • 1970-01-01
    • 2018-10-30
    • 1970-01-01
    • 2019-01-05
    • 2015-11-10
    相关资源
    最近更新 更多