codeigniter - 使用 codeigniter 向所有时事通讯成员发送电子邮件

标签 codeigniter email newsletter

我想使用 codeigniter 库向我的时事通讯成员发送电子邮件,并且我想在电子邮件内容中提及每个成员的电子邮件地址。为此,我使用 foreach 循环 来一封一封地发送电子邮件。 问题是代码只向我的时事通讯的一个成员(第一个成员)发送电子邮件。我检查了我的代码,它从数据库中获取成员并打印出所有成员。

这是我的模型:

function send_news()
{
    $subscribers = $this->get_subscriber_data();
    foreach($subscribers as $subscriber)
    {
        $this->load->helper('typography');

        //Format email content using an HTML file
        $data['news_Title'] = $this->input->post('news_Title');
        $HTML_Message = $this->load->view('admin/includes/newsletter_html_format', $data, true);

        $config['mailtype'] = 'html';
        $this->email->initialize($config);

        $this->email->from('newsletter@site.com', 'newsletter of site.com');
        $this->email->to($subscriber->subscriber_Email);
        $this->email->subject('newsletter of site.com');
        $this->email->message($HTML_Message);

        return $this->email->send();
    }

}

这就是我获取订阅者列表的方式:

function get_subscriber_data($options = array())
{
    $query = $this->db->get('mg_newsletter');

    if(isset($options['subscriber_Id']))
        return $query->row(0);

    return $query->result();
}

当我尝试回显 $subscriber->subscriber_Email 时,它会一个接一个地打印数据库中的所有电子邮件。但它不会向所有人发送电子邮件。我做错了什么?!

最佳答案

使用

 $this->email->clear()

正如 codeignitor 所说: 将所有电子邮件变量初始化为空状态。如果您在循环中运行电子邮件发送功能,允许在循环之间重置数据,则可以使用此功能。

foreach ($list as $name => $address)
{
    $this->email->clear();

    $this->email->to($address);
    $this->email->from('your@example.com');
    $this->email->subject('Here is your info '.$name);
    $this->email->message('Hi '.$name.' Here is the info you requested.');
    $this->email->send();
}

如果将参数设置为 TRUE,所有附件也将被清除。然后告诉我们

关于codeigniter - 使用 codeigniter 向所有时事通讯成员发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19740023/

相关文章:

php - Mysql 连接多列

javascript - 如何使用jquery从附加的html中获取选择内的选项文本?

php - Pear Mail Queue - 日志/记录?

html - 内容管理通讯/电子杂志?

html - 如何在电子邮件 html 中制作带有文字的可调节分隔线?

html - Outlook 2010 时事通讯中的不良图像

mysql - 如何使用条件日期现在显示来自mysql的数据

javascript - 是否可以在页面正文中加载 Jquery

c# - -ERR 超过登录限制 15 分钟。减少对 POP3 服务器的请求频率

linux - 暂停/禁用特定电子邮件帐户。 Linux whm cpanel