1

I have a issue when sending email to codeigniter.

    $config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'email@gmail.com',
'smtp_pass' => 'xxxxx',
'mailtype'  => 'html', 
 'charset'   => 'iso-8859-1'

);

$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->to($user['company_email']);
$this->email->from('noreply@email.com', 'COMPANY');   
$this->email->subject('Password reset');
$this->email->message('You have requested a code. Here is your code: '. $reset['return_pass']);  
    $this->email->send();

At some time, I can send email with no problem but if I use it multiple times or multiple user use this send email(for forgot password), googlemail is unable to connect to ssl://smtp.googlemail.com:465 (Connection timed out) and the email will not be received by the user. How can I fix this issue ? is this a security issue with googlemail?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Vincent
  • 852
  • 6
  • 29
  • 67
  • possible duplicate of http://stackoverflow.com/questions/1555145/sending-email-with-gmail-smtp-with-codeigniter-email-library – Nouphal.M Feb 11 '14 at 03:53
  • possible duplicate of rate limiting explained in http://stackoverflow.com/questions/626421/how-can-i-work-with-around-gmails-smtp-outbound-sending-limits – Patrick Moore Feb 11 '14 at 03:56
  • 1
    i tried the possible duplicate and i still have errors. my code works when sending single email. but when i send it multiple times for testing i receive the error. please check my problem. thanks – Vincent Feb 11 '14 at 04:02
  • 1
    @SetSailMedia - my problem is that my code is working BUT when multiple user send simultaneously, googlemail blocks it and it will have an error – Vincent Feb 11 '14 at 05:11
  • 1
    What is the error? The problem is that Google has rate limits on outbound SMTP connections; so if you have multiple attempts simultaneously, Google will block the later attempts. You need to almost queue the emails and send them out every __ seconds or minutes. – Patrick Moore Feb 11 '14 at 05:44
  • 1
    @SetSailMedia my error is this: Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Connection timed out), and the user will not receive any email. is there other way to use as host ? – Vincent Feb 11 '14 at 05:49
  • 1
    What is the email library you are using? You might try something like [phpmailer](http://phpmailer.worxware.com/) – Patrick Moore Feb 11 '14 at 05:53
  • 1
    @SetSailMedia the library that i am using is on the codeigniter. – Vincent Feb 11 '14 at 05:58
  • 1
    check this http://stackoverflow.com/questions/6310573/gmail-smtp-not-working-in-my-hosting-using-codeigniter-framework – Dexter May 01 '14 at 05:48

1 Answers1

1

I had a similar issue. First, check the junk mail because as I was testing mine Google decided that they were junk and started sorting them in there.

I found that the sending mail using this protocol to multiple users was very unreliable, so I simply ran a loop to send the mails:

function sendEmail($user){
     $config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.gmail.com',
        'smtp_port' => 465,
        'smtp_user' => 'email@gmail.com',
        'smtp_pass' => 'xxxxx',
        'mailtype'  => 'html', 
        'charset'   => 'iso-8859-1'
     );

    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");
    $this->email->to($user);
    $this->email->from('noreply@email.com', 'COMPANY');   
    $this->email->subject('Password reset');
    $this->email->message('You have requested a code. Here is your code: '.
    $reset['return_pass']);  
    $this->email->send();
}


$users = array("person1@test.com", "person2@test.com");

foreach($users as $user){
    sendMail($user);
}
RonnyKnoxville
  • 6,166
  • 10
  • 46
  • 75