使用CodeIgniter发送电子邮件时收到PHP错误 [英] Sending emails with CodeIgniter getting PHP error
问题描述
我正在尝试自学Codeignighter,目前正在学习发送电子邮件。
im trying to teach myself codeignighter and currently learning sending emails.
我正在尝试加载电子邮件库,并且不断收到未定义的属性:Email :: $
I am trying to load the email library and i keep getting "Undefined property: Email::$load" error.
我已经尝试了最后一个小时来查找问题,但无法找出问题所在,我们将不胜感激。
Ive tried for the last hour to find the problem but cant find out whats wrong, any help is much appreciated.
我的 email.php
<?php
class Email extends CI_Controller
{
function __construct()
{
parent::get_instance();
}
function index()
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '****s@gmail.com',
'smtp_pass' => '******'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('****@gmail.com' , 'joe blog');
$this->email->to('****@gmail.com');
$this->email->subject('this is a test');
$this->email->message('it is working .... great!');
if($this->email->send())
{
echo 'your email was sent';
}
else
{
show_error($this->email->print_debugger());
}
}
}
推荐答案
我有相同的错误。
尝试加载电子邮件库,然后像这样配置电子邮件:
Try to load email library, and then the email configuration like this:
// email
$this->load->library('email');
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => '********@gmail.com', // your user.
'smtp_pass' => '****' // your password
);
$this->load->library('email', $config);
在这里,您对此有官方记录:
Here you have the official documentarion about it:
http://www.codeigniter.com/user_guide/libraries/email.html
致谢。
也正如@ devpro
also as mentioned from @ devpro
使用
parent::__construct();
这篇关于使用CodeIgniter发送电子邮件时收到PHP错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!