sending emails to user with id extracted from array

I have code which import CSV data in mysql with php, import is working fine but i need additional function which will send email to user by searching user_id from csv. I had converted csv to array $csv_array,

user_id     order    part

1           test     phone
1           another  pad
2           all      tab

Now, code will search user and get user_email from user database and then send email to user.

foreach ($csv_array as $row) {

                $this->load->library('email');
                $this->load->library('parser');

                $email = $this->admin_model->getEmailNotification();

                $user = $this->model->getUserShipment($row['user_id']);

                if(count($user) == 1)
                {
                    $data = array(  
                        'user_firstname' => $user->user_firstname,
                        'user_lastname' => $user->user_lastname,
                        'user_email' => $user->user_email,
                        );

                    $subject = 'Your Order has been shipped';
                    $message = $this->parser->parse('templates/update', $data, TRUE);

                    $config['protocol'] = $email->email_protocol;
                    $config['smtp_host'] = $email->email_host;
                    $config['smtp_user'] = $email->email_address;
                    $config['smtp_pass'] = $email->email_password;
                    $config['smtp_port'] = $email->email_port;
                    $config['newline']    = "\r\n";

                    $this->email->initialize($config);

                    $this->email->from($email->email_address);
                    $this->email->to($user->user_email);  
                    $this->email->subject($subject);
                    $this->email->message($message);        

                    $this->email->send();
                }


            }

Now with this i have two problems,

  1. This will send email for each row, but i want to send only 1 email with two orders, example, in above table, user_id 1 will get only 1 email with order and part information,

  2. Also, how will i create array to pass in template for user_id-1 -> order and parts to put in table inside template?

Thanks,

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s