1
我想一个发送电子邮件通讯的一些人,他们的地位是在数据库的活动,而我做了,但我也想送一个退订链接以每封电子邮件,我也做了,但我得到一些错误的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 = '[email protected]';
$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.";
}
}
好你个附加在每个循环迭代新链接$消息 - 所以还有什么你希望发生......? – CBroe
您是否尝试过使用$这个 - >的电子邮件 - >清除(TRUE)解释这里http://www.codeigniter.com/user_guide/libraries/email.html#CI_Email::clear – user4419336
感谢您的帮助 –