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
感謝您的幫助 –