I need help setting up Gmail SMTP in CodeIgniter’s email library as I’m facing connection issues. Here’s how my code looks:
<?php
class EmailSender extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->library('email');
}
public function index()
{
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = '[email protected]';
$config['smtp_pass'] = 'yourpassword';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'text';
$config['validation'] = TRUE;
$this->email->initialize($config);
$this->email->from('[email protected]', 'Your Name');
$this->email->to('[email protected]');
$this->email->subject('Test Email');
$this->email->message('This is a test to see if the email works.');
$this->email->send();
echo $this->email->print_debugger();
$this->load->view('email_sent_view');
}
}
When I try to use port 465, I encounter a timeout error from fsockopen(). If I switch to ports 25 or 587, I receive SSL errors. I prefer to use CodeIgniter’s email library instead of PHPMailer. What changes should I make for it to work correctly?