Hi everyone,
I have a codeigniter 3 based website hosted on Godaddy shared hosting where i'm trying to add email functionality. I just read few articles online where people have recommended gmail smtp instead of PHP's built-in mail() function. So, when i tried to implement gmail smtp through codeigniter's email library then i got some errors. I don't know how to fix it now.
Here is the content of my /application/config/email.php file:-
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.gmail.com";
$config['smtp_user'] = "[email protected]";
$config['smtp_pass'] = "my_password";
$config['smtp_port'] = "465";
$config['mailtype'] = "html";
$config['charset'] = "utf-8";
$config['newline'] = "\r\n";
And below is the error message that i got using $this->email->print_debugger()
function:-
The following SMTP error was encountered: 111 Connection refused
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
It'll be great if you people can help me fix the email functionality of my website.
Thanks in advance.
Basically the problem with Godaddy shared hosting is that they block all mail servers (i.e. gmail) except their own from accessing ports 465, 587 and 25 which are mostly used for outbound SMTP. That's why your connection is refused.
To fix this, Godaddy provides a really simple and straight forward solution. That is, you must use Godaddy servers for sending emails.
Use below configuration inside your /application/config/email.php file:-
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$config['protocol'] = "mail";
$config['smtp_host'] = "localhost";
$config['smtp_user'] = "";
$config['smtp_pass'] = "";
$config['smtp_port'] = 25;
$config['mailtype'] = "html";
$config['charset'] = "utf-8";
$config['newline'] = "\r\n";