Islam Zedan
Islam Zedan

Reputation: 656

Sending Emails using SMTP Gmail Codeigniter work local but gives error on the host

I am using email class in Codeigniter to send email throw Gmail smtp Here is my setting for this:

$this->load->library('email');
$config['protocol'] = 'smtp';
$config['wordwrap'] = TRUE;
$config['smtp_host'] = 'smtp.gmail.com';
$config['smtp_user'] = '[email protected]';   // I write my correct email here
$config['smtp_pass'] = 'xxxxxxxxx';         // I write my correct password here
$config['smtp_port'] = 587;
$config['smtp_crypto'] = "tls";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";

$this->email->initialize($config);

$this->email->from('[email protected]', 'My Name');
$this->email->to('[email protected]'); // I write onther email here
$this->email->subject('test gmail smtp');
$this->email->message('success :)');
if (!$this->email->send()) {
    echo $this->email->print_debugger();
}

I have tried it on my local machine the code works fine and all of the emails have been received. After I have uploaded my script to my GoDaddy host it gives me this warning:-

fsockopen(): unable to connect to smtp.gmail.com:587 (Connection timed out)

and email print_debugger(); print this error:-

The following SMTP error was encountered: 110 Connection timed out Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

And I have tried this code on another host (Bluehost) it gives me the same warning and error.

Any one know where I go wrong?

Upvotes: 0

Views: 1153

Answers (2)

Kalana Demel
Kalana Demel

Reputation: 3266

Port 587 is blocked by go daddy for outgoing smtp connections, use one of the following ports according to your requirement as specified.

non SSL - 80, 3535, 25

SSL - 465

https://www.godaddy.com/help/what-do-i-do-if-i-have-trouble-connecting-to-my-email-account-319

Upvotes: 1

Vahe Galstyan
Vahe Galstyan

Reputation: 1731

check php.ini file on production server. If you have ;extension=php_openssl.dll in php.ini change it to extension=php_openssl.dll (remove coma, and restart apache or nginx).

Upvotes: 0

Related Questions