php - 如何在codeigniter 3中发送电子邮件
问题描述
我想在 codeigniter 3 中发送电子邮件,但没有做到,我已经设置了我的 smtp 设置,但没有工作有没有办法在 codeingter 3 中发送电子邮件,它谷歌了几次,但未能提前解决它。这是我的控制器
$this->db->query("INSERT INTO newsletter_subscribers (name,email, status, date_created, date_updated) VALUES ('".$options['name']."','".$options['email']."', 'inactive', NOW(), NOW())");
$this->session->set_userdata('newsletter_sess', $options['email']);
$query = $this->db->query("select subject, html_body, text_body, allowed_vars from email_template where tempid = 12");
if ($query->num_rows() > 0){
$objEmailTemplate = $query->row();
}
//%SITE_TITLE%, %SITE_URL%, %EMAIL%, %NAME%, %LINK_URL%
$allowed_vars = explode(', ', $objEmailTemplate->allowed_vars);
$rep_vars = array(site_url(),
SITE_NAME, $options['email'],
$options['email'],
base_url().'front/subscribed/'.base64_encode($options['email']));
$subject = str_replace($allowed_vars, $rep_vars, $objEmailTemplate->subject);
$html_body = str_replace($allowed_vars, $rep_vars, $objEmailTemplate->html_body);
$text_body = str_replace($allowed_vars, $rep_vars, $objEmailTemplate->text_body);
$admin = $this->main_model->getSettingData('contact_email');
$contact_email = $admin->value;
// Configure email library
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://ssmtp.gmail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = 'hussainshahid006@gmail.com';
$config['smtp_pass'] = '******';
$config['mailtype'] = 'html';
// Load email library and passing configured values to email library
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from($contact_email);
$this->email->to($options['email']);
$this->email->subject($subject);
$this->email->message($html_body);
$this->email->send();
解决方案
推荐阅读
- postgresql - Postgresql AFTER UPDATE 触发器 OLD 没有字段
- java - Hibernate 在映射 Java 类时不添加引用约束(Spring Boot 应用程序)
- php - 我正在尝试在 Laravel 中混合数据透视表值
- visual-studio-2017 - 新安装的 Visual Studio 2017 中的 Visual C# 下缺少 Web 模板
- python - 如何删除打印列表中的最后一行?
- amazon-web-services - 拒绝 S3 存储桶内特定文件夹的特定用户的权限
- javascript - 通过回调的 Ajax
- java - 为对象设置必填字段
- vb.net - 多次点击增量
- go - 无法连接到代理“证书由未知机构签署”