Отправить письмо на все строки из MySQL в codeigniter - PullRequest
0 голосов
/ 31 мая 2019

Мне нужно отправить электронные письма всем строкам таблицы базы данных с соответствующими данными.Я могу отправлять отдельные письма по их идентификатору, но теперь мне нужно отправить оптом.я сделал в чистом php, но в codeigniter не в состоянии выяснить.как это сделать.

мой контроллер

     public function autoformcomplete()
        {
            $this->load->model('admin/Reminder_model');
            $datan = $this->Reminder_model->autoformemail();

//this should be in whileloop, that i am not able to figure out
             $email = $datan[0]['email'];
                $config = array(
                        'protocol'  => 'smtp',
                        'smtp_host' => 'email-smtp.eu-west-1.amazonaws.com',
                         'smtp_port' => 587,
                        'smtp_crypto' => 'tls',
                        'smtp_user' => 'user',
                         'smtp_pass' => 'pass',
                        'mailtype'  => 'text',
                         'charset'   => 'utf-8',
                         );
              $this->email->initialize($config);
              $this->email->set_mailtype("html");
              $this->email->set_newline("\r\n");
              $this->email->set_crlf("\r\n");
              $subject = "Complete Your Partially Filled Application-".$appid."";
              $data['datan'] = $datan;
              $mesg = $this->load->view('email/reminder/form_complete',$data,true);
              $this->email->to($email);
              $this->email->from('mail@mail.com','My Company');
              $this->email->subject($subject);
              $this->email->message($mesg);
              $this->email->send();
              echo "sent";

        }

моя модель

public function autoformemail(){

        $this->db->order_by('id', 'DESC');
        $query = $this->db->get('appstbldata');
        return $query->result_array();

       }

1 Ответ

1 голос
/ 31 мая 2019

Просто используйте цикл foreach

public function autoformcomplete() {
    $this->load->model( 'admin/Reminder_model' );
    $datan = $this->Reminder_model->autoformemail();

    foreach ( $datan as $index => $val ) {
        // $val now references the current pointer to an element in your $datan array
        $email  = $val['email'];
        $config = array(
            'protocol'    => 'smtp',
            'smtp_host'   => 'email-smtp.eu-west-1.amazonaws.com',
            'smtp_port'   => 587,
            'smtp_crypto' => 'tls',
            'smtp_user'   => 'user',
            'smtp_pass'   => 'pass',
            'mailtype'    => 'text',
            'charset'     => 'utf-8',
        );
        $this->email->initialize( $config );
        $this->email->set_mailtype( "html" );
        $this->email->set_newline( "\r\n" );
        $this->email->set_crlf( "\r\n" );
        $subject       = "Complete Your Partially Filled Application-" . $appid . "";
        $data['datan'] = $datan;
        $mesg          = $this->load->view( 'email/reminder/form_complete', $data, true );
        $this->email->to( $email );
        $this->email->from( 'mail@mail.com', 'My Company' );
        $this->email->subject( $subject );
        $this->email->message( $mesg );
        $this->email->send();
        echo "sent";
    }

}

Я не знаю, какая у вас точка линии $data['datan'] = $datan;, хотя

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...