0

I have a PHP application that uses CodeIgniter Email library class to send thousands of emails over SMTP protocol. The issue is, for each email sent, it uses a fresh connection with the SMTP server. How can I use a persistent connection in this case ?

For example, Suppose I send 1000 emails and then I do authentication once again and send 1000 more emails and so on.

Gabe
  • 84,912
  • 12
  • 139
  • 238
Aniruddha Shival
  • 113
  • 3
  • 10

3 Answers3

0

Try using "bcc_batch_mode" in your email class.

See here for more info: https://codeigniter.com/user_guide/libraries/email.html

Paananen
  • 13
  • 3
Laurence
  • 58,936
  • 21
  • 171
  • 212
  • I cant use bcc_batch_mode. Each email is unique and there are no BCC addresses to use. I just want to avoid SMTP authentication step for each and every email sent. It is OK to use authentication once in a while, but not for every email. – Aniruddha Shival Apr 10 '12 at 14:07
  • 1
    No one else can access docs on your localhost - I think this is the same page http://codeigniter.com/user_guide/libraries/email.html – Mike B Apr 10 '12 at 14:20
0

since i didnt read your code, am going to post the one which they have put in the documentation ..

$this->email->clear()

Initializes all the email variables to an empty state. This function is intended for use if you run the email sending function in a loop, permitting the data to be reset between cycles.

foreach ($list as $name => $address)
{
    $this->email->clear();

    $this->email->to($address);
    $this->email->from('your@example.com');
    $this->email->subject('Here is your info '.$name);
    $this->email->message('Hi '.$name.' Here is the info you requested.');
    $this->email->send();
}

and if this didnt work with you, i have another thing which is much more suitable and to be honest better than the builtin mail class, try to use the Swift-mailler library which can solve most of your problem ..

Zaher
  • 1,120
  • 7
  • 18
  • I might give a try to Swift-mailer library at a later stage, but at the moment, I am looking for a solution with current CodeIgniter email library. I am not sure how could this function (email->clear) would help me to achieve persistent SMTP connection. My aim is to speed up email sending using SMTP. Something like SMTP Keep Alive feature with phpmailer library class. – Aniruddha Shival Apr 11 '12 at 05:54
  • Yes. I am already using that function in my email sending code. It does not help me in achieving persistent SMTP connection – Aniruddha Shival Apr 11 '12 at 06:00
0

Simple like that:

Forget about CI's Email lib unless you'd be patient to change the core of the class... As a good alternative, use the PHPMailer class, put it in your CI/Application/libraries and with that you just need to set the property $SMTPKeepAlive to true, do what you want to do and after call SmtpClose();

I have a good implementation here using CI, I keep the SMTP servers in the database and all mailing stuffs are "ezfied" by a model I've wrote.

Rgds