CodeIgniter邮件发送基础
本实例详解了CodeIgniter框架中简易邮件发送类的用法,供读者参考借鉴。
CI框架能够显著减少PHP开发中的代码量,是初学者理想的工具选择。
接下来展示一个基础的邮件发送操作示例。
function email()
{
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.163.com';
$config['smtp_user'] = 'jb51@163.com';//这里写上你的163邮箱账户
$config['smtp_pass'] = 'jb51;';//这里写上你的163邮箱密码
$config['mailtype'] = 'html';
$config['validate'] = true;
$config['priority'] = 1;
$config['crlf'] = "\r\n";
$config['smtp_port'] = 25;
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$this->email->from('jb51@163.com', '本站');//发件人
$this->email->to('123456789@qq.com');
$this->email->message('哈哈,测试邮件发送');
$this->email->send();
echo $this->email->print_debugger();
}
若偏好使用配置文件而非代码设定参数,可新建email.php文件并将$config数组写入其中,保存至config/email.php目录后系统会自动加载。此时无需再手动调用$this->email->initialize()进行初始化。
期望上述内容对使用CodeIgniter进行PHP编程的用户有所助益。