简体   繁体   中英

connection time out issue when sending email for codeigniter

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?

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM