gmail smtp使用codeigniter框架无法在我的主机中工作

时间:2011-06-10 18:29:53

标签: email codeigniter ssl smtp gmail

我希望使用gmail smtp将用户信息发送到已注册的电子邮件。

我正在使用的代码在我的localhost中工作正常,但是当我改为共享主机时,它出现了以下错误。

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)

这是我的电子邮件配置

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

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

$this->email->from('admin@lalala.com','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!!!';}

我尝试检查我的共享主机openssl是否启用。我发现了这个

OpenSSL的 启用OpenSSL支持
OpenSSL版本OpenSSL 0.9.8e-fips-rhel5 2008年7月1日

如果启用了openssl。我的代码中仍然会出现什么错误?

我开始对使用我的localhost进行开发感到沮丧,当它上传到共享主机时,它出现了很多错误。

任何帮助都会很感激!! thx in advanced

2 个答案:

答案 0 :(得分:15)

看起来共享主机中的ur ssl端口已关闭, 使用此代码检查它是否已打开。

$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";

答案 1 :(得分:4)

在较新的php中有测试脚本的更新 版本:

<?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";



?>