【发布时间】:2017-12-05 01:21:28
【问题描述】:
我正在努力在 codeigniter 中循环发送电子邮件。 实际发生的事情是我正在收到电子邮件,但它没有显示我包含的消息。以下是脚本:
<?php
Class Email extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'myemail',
'smtp_pass' => 'mypass',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'send_multipart' => FALSE
);
$this->load->library('email', $config);
$this->load->database();
$query = $this->db->query('SELECT email FROM users');
// $this->email->initialize($config);
// $this->email->set_newline('\r\n');
foreach ($query->result() as $row)
{
$this->email->clear();
$this->email->set_newline("\r\n");
$this->load->library('email',$config);
$this->email->from("mymail","myname");
$this->email->to($row->email);
$this->email->subject("THIS IS AN EMAIL TEST");
$this->email->message('Hello, We are <strong>Example Inc.</strong>');
$this->email->set_mailtype("html");
if($this->email->send())
{
echo "Your Mail send";
}
else
{
show_error($this->email->print_debugger());
}
}
echo 'Total Results: ' . $query->num_rows();
}
}
?>
我期待 Hello, We are <strong>Example Inc.</strong>' 电子邮件中的这条消息,但我实际得到的是
电子邮件中没有消息。我哪里出错了。
【问题讨论】:
-
删除
html标签并检查。删除<strong></strong> -
删除 html 标签不起作用。如果我在视图文件夹中传递任何页面模板存储,那么它工作正常。但是,如果我在
message()中将字符串作为消息传递,则它不起作用。send_multipart是假的,这就是它发生的原因? -
从 foreach 循环中移除这段代码 $this->load->library('email',$config);因为您已经在循环之外加载电子邮件库
标签: codeigniter email codeigniter-2