Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
746 views
in Technique[技术] by (71.8m points)

email - 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("
");

$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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>
";
else
    echo "www.google.com -  ok<br>
";


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


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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...