Welcome Guest, Not a member yet? Register   Sign In
Sending bulk email with comma separated
#1

Hi;

I send comma separated (or array) as $recepients. Emails get sent as bulk and everyone gets their copy. But everyone sees the receives as benscopy@***.com. They don't see it as their own email. How can I do it so they see it as their own email it's kinda confusing.

Thanks
PHP Code:
public function send_email($recepients$template)
 {
 
$this->load->library('email');
 
$config['bcc_batch_mode'] = true;
 $this->email->initialize($config);
 
$this->email->clear(TRUE);
 
$this->email->from('support@**.com''Ben ***'); 
 
$this->email->to('benscopy@***.com');
 
$this->email->bcc($recepients);
 
$message $this->load->view('email_template',$data,TRUE);
 
$this->email->message($message);
 
$this->email->send();
 } 
Reply
#2

That's because you're sending it TO "[email protected]", and BCCing everyone else. If you want it to go TO them, then send it TO them and don't BCC them. So you'd have to loop through them all and send an individual email. You'll be sending a lot more mail, but it will do what you want. This is just standard email stuff and doesn't really have to do with the CI email library. The same would happen if you did the same thing in your regular email client.
Reply
#3

Also, where is $data coming from here? Seems you should be getting an error unless you didn't post your complete for that method.
PHP Code:
$message $this->load->view('email_template',$data,TRUE); 
Reply
#4

(03-31-2015, 08:02 AM)CroNiX Wrote: That's because you're sending it TO "[email protected]", and BCCing everyone else.  If you want it to go TO them, then send it TO them and don't BCC them. So you'd have to loop through them all and send an individual email. You'll be sending a lot more mail, but it will do what you want.
Any potential problems? I thought it might jam the server etc?

About the code:

Yes I didn't post all code I thought no one's gonna read it Wink Here I paste it.

Basically I mean scheduled emails. I know MailChimp etc etc are better but I suck at API's too and I don't have time to learn api at this moment.

I was wondering if I missed anything and there are any obvious flaws in this script. It works fine!

I don't expect to send more than 500 at a time. I only send to those who joined within past week. So I don't really worry about that loop.

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Daily_email_cron extends CI_Controller 
    
{
 
   public function index()
 
       {
 
           $day 0;
 
           $sent = array();
 
           $recepients = array();
 
           while($day 6)
 
               {
 
                   $day++;
 
                   $days[$day]=array('day'=>date('Y-m-d',strtotime($day.' days ago')));
 
               }
 
           foreach($days as $val=>$row)
 
               {
 
                   $query $this->db->get_where('eMember_members_tbl', array('membership_level' => 5'member_since'=>$row['day']));
 
                   if($query->num_rows()>0)
 
                       {
 
                           $recepients = array();
 
                           foreach ($query->result() as $row)
 
                               {
 
                                   if (!filter_var($row->emailFILTER_VALIDATE_EMAIL) === false
 
                                       {
 
                                           $recepients[]=$row->email;
 
                                          
                                    $template 
$val;
 
                               }
 
                           $this->send_email($recepients$template);    
                            
                            foreach
($recepients as $recepient)
 
                               {
 
                                   $sent[]=array('recepient'=>$recepient'date_sent'=>date('Y-m-d'), 'message'=>$template);
 
                               }
 
                          
                
}
 
           $this->db->insert_batch('sent_emails'$sent);  
        
}

 
       
    public 
function send_email($recepients$template)
 
       {
 
           $this->load->library('email');
 
           $email_template $this->db->get_where('**free_mini_course', array('id' => $template));
 
           $config['mailtype'] = 'html';
 
           $this->email->initialize($config);
 
           $this->email->clear(TRUE);
 
           $this->email->from('support@**.com''Ben **'); 
 
           $this->email->to('support@**.com');
 
           $this->email->bcc($recepients);
 
           $this->email->subject($email_template->result()[0]->title);
 
           $data['message'] = $email_template->result()[0]->message;
 
           $message $this->load->view('email_template',$data,TRUE);
 
           $this->email->message($message);
 
           //$this->email->send();
 
          
    

Reply
#5

In your send_email(), just loop through recipients and set the TO as their individual address and don't use BCC. That will make the email behave as you outlined in your first post by sending directly TO them. If you're worried about "jamming" the email server, you could always put a small delay in the loop, but most email servers should handle it with no problems.
Reply
#6

(03-31-2015, 03:45 PM)CroNiX Wrote: In your send_email(), just loop through recipients and set the TO as their individual address and don't use BCC. That will make the email behave as you outlined in your first post by sending directly TO them. If you're worried about "jamming" the email server, you could always put a small delay in the loop, but most email servers should handle it with no problems.
So are you saying there won't be any potential errors based on my requirements?
Thanks
Reply
#7

It should, but I don't know your server setup. How often are you doing this? You say there shouldn't be more than like 500 at a time, but is that every day, once a week, etc? You can always turn it into a cron job and run it every few hours or once a day so there aren't so many being sent at once if your worried about that, but 500 emails being sent in a loop shouldn't be a problem, but again that depends on your server resources, etc.
Reply
#8

Check your provider's terms to determine how many emails they permit you to send (usually they will have a maximum number per hour). If the number of recipients is lower than the maximum, you should be fine, as long as you're not sending emails to these recipients frequently. Otherwise, you'll probably want to build a queue and process them on a schedule to make sure you don't get your site (or its access to send email) shut down.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB