首页 > 解决方案 > 如何在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();

标签: phpcodeigniter

解决方案


推荐阅读