Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gmail smtp not working in my hosting using codeigniter framework

i wish to use gmail smtp to send user information to the registered email.

The code that i am using is working fine in my localhost, but when i changed into shared hosting it come out with the below error.

A PHP Error was encountered
Severity: Warning

Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.googlemail.com:465 (Connection timed out)

Filename: libraries/Email.php

Line Number: 1652

A PHP Error was encountered
Severity: Warning

Message: fwrite(): supplied argument is not a valid stream resource

Filename: libraries/Email.php

Line Number: 1795

.... (more error msg here)

An Error Was Encountered
The following SMTP error was encountered: 110 Connection timed out
Unable to send data: AUTH LOGIN
Failed to send AUTH LOGIN command. Error: 
Unable to send data: MAIL FROM:


from: 
The following SMTP error was encountered: 
Unable to send data: RCPT TO:

to: 
The following SMTP error was encountered: 
Unable to send data: DATA

.... (more error msg here)

Here's my email config

$pass = $this->generatePassword('6');

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

$this->email->from('[email protected]','Title');
$this->email->to($this->input->post('email'));

$this->email->subject('Subject here');
$this->email->message('Your login username is '.$this->input->post('username').'<br/>'.'Password is '.$pass);

if (!$this->email->send()){
  show_error($this->email->print_debugger());
}else{ echo 'YEAH!!!';}

i try to check my share hosting openssl whether is enabled or not. and i found this

openssl OpenSSL support enabled
OpenSSL Version OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008

If openssl is enabled. still what will be the mistake in my code?

I start to be frustrated to use my localhost to develop and when its uploaded to share hosting, it came out wit lots of error.

Any help would be appreciate!! thx in advanced

like image 775
Bravo Net Avatar asked Jun 10 '11 18:06

Bravo Net


2 Answers

Looks like ur ssl port in shared hosting is close, use this code to check if it is open.

$fp = fsockopen("www.google.com", 80, &$errno, &$errstr, 10); // work fine
if (!$fp)
    echo "www.google.com -  $errstr   ($errno)<br>\n";
else
    echo "www.google.com -  ok<br>\n";


$fp = fsockopen("smtp.gmail.com", 465, &$errno, &$errstr, 10); // NOT work
if (!$fp)
    echo "smtp.gmail.com 465  -  $errstr   ($errno)<br>\n";
else
    echo "smtp.gmail.com 465 -  ok<br>\n";


$fp = fsockopen("smtp.gmail.com", 587, &$errno, &$errstr, 10); // NOT work
if (!$fp)
    echo "smtp.gmail.com 587  -  $errstr   ($errno)<br>\n";
else
    echo "smtp.gmail.com 587 -  ok<br>\n";
like image 160
Aman Avatar answered Oct 14 '22 09:10

Aman


there is update for test script in newer php version:

<?php

    $fp = fsockopen("www.google.com", 80, $errno, $errstr, 10); // work fine
    if (!$fp)
        echo "www.google.com -  $errstr   ($errno)<br>\n";
    else
        echo "www.google.com -  ok<br>\n";


    $fp = fsockopen("smtp.gmail.com", 465, $errno, $errstr, 10); // NOT work
    if (!$fp)
        echo "smtp.gmail.com 465  -  $errstr   ($errno)<br>\n";
    else
        echo "smtp.gmail.com 465 -  ok<br>\n";


    $fp = fsockopen("smtp.gmail.com", 587, $errno, $errstr, 10); // NOT work
    if (!$fp)
        echo "smtp.gmail.com 587  -  $errstr   ($errno)<br>\n";
    else
        echo "smtp.gmail.com 587 -  ok<br>\n";



?>
like image 31
Rami Kellesly Avatar answered Oct 14 '22 09:10

Rami Kellesly