Home >Backend Development >PHP Tutorial >How to Fix 'Connection Timed Out' and 'SSL Operation Failed' Errors When Sending Emails via Gmail SMTP with CodeIgniter?

How to Fix 'Connection Timed Out' and 'SSL Operation Failed' Errors When Sending Emails via Gmail SMTP with CodeIgniter?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-18 13:51:16248browse

How to Fix

Sending Email via Gmail SMTP Using CodeIgniter's Email Library

An error occurs while implementing email sending via Gmail SMTP with the CodeIgniter email library, indicating a "Connection timed out" or "SSL operation failed" error. To resolve this:

For SMTP Connection Timed Out:

  • Ensure the Gmail account's "Less secure app access" setting is enabled in the Google account settings.

For SSL Operation Failure:

  • Use port 465 with TLS encryption instead of port 587.
  • Modify the SMTP host to ssl://smtp.googlemail.com instead of ssl://smtp.gmail.com.

Code:

$config = [
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'xxx',
    'smtp_pass' => 'xxx',
    'mailtype' => 'html',
    'charset' => 'iso-8859-1'
];
$this->load->library('email', $config);
$this->email->set_newline("\r\n");

// Set to, from, message, etc.

$result = $this->email->send();

This code modification should resolve the connection timeouts and SSL operation failures.

The above is the detailed content of How to Fix 'Connection Timed Out' and 'SSL Operation Failed' Errors When Sending Emails via Gmail SMTP with CodeIgniter?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn