如何向codeigniter中的所有订阅者发送简报图像

时间:2017-07-03 07:39:09

标签: mysql codeigniter email

我正在尝试将简报图像发送给我所有订阅者的Codeigniter,但收到未定义的属性错误,有人可以帮我这个吗?我的代码是

查看

     <form method="POST" action="<?php echo 
    base_url();>Newsletter_Controller/sendnewsletter" 
     enctype="multipart/form-data" >
            <div class="box-body">
            <div class="form-group col-lg-4 col-md-4 col-sm-12">
                <label for="newsletter" class="col-xs-12">Upload 
                 Newsletter</label>
                 <input type="file" id="newsletter" name="newsletter" 
                 class="col-xs-12"> 
            </div>  

            <div class="clearfix"></div>
            <!-- /.box-body -->
            <div class="box-footer">
                <button type="submit" class="btn btn-primary">Send to 
                   Subscriber's</button>
            </div>
        </div>
        </form>

我的控制器

2 个答案:

答案 0 :(得分:0)

请查找下面提到的sudo代码。实施和改变它取决于您的要求。

// This will use to send individual email to each user individually
public function sendnewsletter(){
    $recipient_list= array();
    $subscribers = // Get all subscribers from database
    $this->load->library('email');
    $this->email->set_header('MIME-Version', '1.0; charset=utf-8');
    $this->email->set_header('Content-type', 'text/html');
    foreach($subscribers as $subscriber):
         $recipient_list[] = $subscriber['email'];
    endforeach;
    $this->email->from('your@example.com', 'Your Name');
    $this->email->to($recipient_list);
    $this->email->subject('Email Test');
    $this->email->message('<img src="/path/to/photo1.jpg" />');
    $this->email->send();

}

如果您需要更多帮助,请与我们联系。

答案 1 :(得分:0)

您可以以html格式发送电子邮件。使用$config['mailtype'] = 'html';

    $this->load->helper('url');
        $this->load->helper('form');
        $this->load->library('email');
                    $config['protocol'] = 'mail';
                    $config['mailtype'] = 'html';
                    $config['mailpath'] = '';
                    $config['charset'] = 'iso-8859-1';
                    $config['crlf'] = '\r\n';
                    $config['wordwrap'] = TRUE;
                    $this->email->initialize($config);
                    $baseurl = base_url();
     $this->email->from('from@demo.com');
     $this->email->to('to@demo.com');

    $content_head   =   '<html>
        <head>
        <title>emailer</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        </head>
    <body bgcolor="#f1f1f1" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
   <table width="600" cellpadding="0" cellspacing="0" border="0" align="center">
                    <tr>
                            <td align="left" valign="top">
   <img src="'.base_url().'assets/images/email_banner.JPG"  width="600" height="137" ></td>
                    </tr>';
$this->email->message($content);            
$this->email->send();