Welcome Guest, Not a member yet? Register   Sign In
Send e-mail stored from database
#1

[eluser]mvn1990[/eluser]
Hi, i need to send e-mail to e-mailadresses stored in a database, i don't know how i have to do this with codeigniter? the table of the database looks like this

Tbl_emails

id
username
email
fk_id_user
#2

[eluser]Frank Rocco[/eluser]
Code:
$query = $this->db->get('Tbl_emails');
$this->load->library('email');
foreach ($query->result() as $row)
{
$this->email->from('youremail@com', 'Your Name');
$this->email->to($row->email);
$this->email->subject('your subject');
$this->email->message('your body');
$this->email->send();
sleep(1);
}
#3

[eluser]InsiteFX[/eluser]
Code:
$query = $this->db->get('Tbl_emails');
$this->load->library('email');
foreach ($query->result() as $row)
{
    $this->email->from('youremail@com', 'Your Name');
    $this->email->to($row->email);
    $this->email->subject('your subject');
    $this->email->message('your body');
    $this->email->send();
    if ( ! $this->email->send())
    {
        // Generate error or handle it!
    }
    else
    {
        $this->email->clear(TRUE);
    }
}

You also need to setup the email conf read the CodeIgniter User Guide Email Class.

InsiteFX
#4

[eluser]Frank Rocco[/eluser]
Thanks for adding the error check.

Don't you have to take out the
Code:
$this->email->send();
to prevent sending twice?
#5

[eluser]InsiteFX[/eluser]
Not if your your doing multiple email sends, which is the way you have it coded.

But be careful some hosting providers will nail you if you send to many in any given time limit.

InsiteFX
#6

[eluser]Frank Rocco[/eluser]
Ok, thanks for the info.




Theme © iAndrew 2016 - Forum software by © MyBB