【问题标题】:CodeIgniter email to multiple people with unsubscribe link giving errors/CodeIgniter 向多人发送电子邮件,取消订阅链接给出错误/
【发布时间】:2017-08-28 12:15:34
【问题描述】:

我想给一些人发送电子邮件简报,他们的状态在数据库中是活动的,我已经完成了,但我也想在每封电子邮件中发送一个取消订阅链接,我也做了,但我得到了一些东西foreach 循环中的错误,因为每次循环运行时,它都会通过电子邮件向用户发送一个额外的 (i+1) 取消订阅链接。我附上代码。

这是我的视图

<form role="form" method="post" action="<?= base_url()?>email/send_newsletter">
<div class="box-body">
     <div class="form-group">
                    <label>Select Multiple Lists</label>
                    <select class="form-control select2" name="lists" data-placeholder="   Select List(s)">
                      <?php foreach ($lists as $list_name){ ?>
                    <option value="<?php echo $list_name['list_id'];?>"><?php echo $list_name['list_name'];?></option>
                    <?php }?>
                    </select>
                  </div>              
                    <div class="form-group">
                      <label for="exampleInputEmail1">Subject</label>
                      <input type="text" name="subject" class="form-control" id="exampleInputEmail1" placeholder="Enter Subject">
                    </div>
                  <script src="<?= base_url()?>assets/ckeditor/ckeditor.js"></script>
                    <div class="form-group">
                      <label for="exampleInputEmail1">Message</label>
                      <textarea name="message" class="form-control" id="editor1" cols="10" rows="5"></textarea>
                <script>

                    CKEDITOR.replace( 'editor1' );
                </script>
                    </div>

                    <div class="form-group">
                      <label for="exampleInputFile">File input</label>
                      <input type="file" id="exampleInputFile">

                      <p class="help-block">Example block-level help text here.</p>
                    </div>
                  </div>


                  <div class="box-footer">
                    <button type="submit" class="btn btn-primary">Submit</button>
    </div>
</form>

这是我的控制器方法

public function send_newsletter()
{
     $lists = $this->input->post('lists');
     $subject = $this->input->post('subject');
     $message = $this->input->post('message');

     $join_str1 = "subscribers.subscriber_list_id=lists.list_id";

     $subscribers =  
     $this->global_model
     ->join_2table('subscribers','lists', $join_str1,['subscriber_list_id'=>$lists,'subscriber_status'=>'Active']); 



    foreach($subscribers as $row) {

        $email_lists = $row['subscriber_email'];
        $random_key = $row['random_key'];   
        $message.=
        "<a href=\"http://xyz.in/abc/unsubscribe/unsubscribe_me/{$random_key}\">Unsubscribe Here</a>";

        $from_email = 'support@xyz.com';
        $this->email->from($from_email, 'CRM'); 
        $this->email->to($email_lists);
        $this->email->subject($subject); 
        $this->email->message($message); 
        $this->email->set_mailtype('html');
        $sendmail = $this->email->send();

    }                 
        //Send mail 
        if($sendmail) 
        {
            echo "Email sent";
        } 
        else 
        {
            echo "email failed.";
        }      
}

【问题讨论】:

标签: php arrays codeigniter email foreach


【解决方案1】:

我解决了问题,我只是添加了两个变量,像这样

foreach($subscribers as $row) {

    $email_lists = $row['subscriber_email'];
    $random_key = $row['random_key'];   
    $message = $this->input->post('message').
    "<a href=\"http://eclabsindia.in/crm_alazizi/unsubscribe/unsubscribe_me/{$random_key}\">Unsubscribe Here</a>";

    $from_email = 'support@indiatestbook.com';
    $this->email->from($from_email, 'CRM ALAZIZI'); 
    $this->email->to($email_lists);
    $this->email->subject($subject); 
    $this->email->message($message); 
    $this->email->set_mailtype('html');
    $sendmail = $this->email->send();

}                 

【讨论】:

    猜你喜欢
    • 2020-07-28
    • 1970-01-01
    • 1970-01-01
    • 2016-03-28
    • 2012-12-02
    • 2019-08-04
    • 2015-05-15
    • 1970-01-01
    • 2018-08-28
    相关资源
    最近更新 更多