SMTP的Gmail误差笨2.1.3(SMTP Gmail error with Codeignit

2019-07-04 00:25发布

我看过很多帖子涉及到这个问题,我已经做了给出的指令,但总是得到同样的错误..

我想用代码点火器2.1.3发送SMTP的Gmail,这是代码:

class Email extends CI_Controller{

function index(){

$config = Array(
'protocol'      => 'smtp',
'smtp_crypto'   => 'ssl',
'smtp_host'     => 'smtp.gmail.com',
'smtp_user'     => 'myEmail@gmail.com',
'smtp_pass'     => '***********',
'smtp_port'     => 25,
'mailtype'      => 'text',
'smtp_timeout'  =>  15, 
'charset'       => 'iso-8859-1'
);
$this->load->library('email', $config);

$this->email->set_crlf("\r\n");
$this->email->set_newline("\r\n");
$this->email->from("myEmail@gmail.com", "myName");
$this->email->to("myEmail@gmail.com");
$this->email->subject("Email Test");
$this->email->message("This is email test");

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

而错误总是这样,

Message: fsockopen(): unable to connect to ssl://smtp.gmail.com:25 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. )

请帮我解决这个错误,谢谢:)

Answer 1:

您需要启用php.ini文件中的SSL在你的服务器配置,您可以检查它是否被启用与否,如果你使用的是XAMPP服务器。 在去PHP信息搜索SSL .........

您需要删除; 扩展之前= php_openssl.dll在php.ini文件此行。

您需要启用OpenSSL的........

我面对这个错误recently.There是在你的代码中的小错误........

function sendMail()
{
    $config = Array(
  'protocol' => 'smtp',
  'smtp_host' => 'ssl://smtp.googlemail.com',
  'smtp_port' => 465,
  'smtp_user' => 'xxx@gmail.com', // change it to yours
  'smtp_pass' => 'xxx', // change it to yours
  'mailtype' => 'html',
  'charset' => 'iso-8859-1',
  'wordwrap' => TRUE
);

        $message = $this->load->view('upload_success','',TRUE);
        $this->load->library('email', $config);
      $this->email->set_newline("\r\n");
      $this->email->from('xxx@gmail.com'); // change it to yours
      $this->email->to('yyy@gmail.com');// change it to yours
      $this->email->subject('Resume from JobsBuddy for your Job posting');
      $this->email->message($message);
      if($this->email->send())
     {
      echo 'Email sent.';
     }
     else
    {
     show_error($this->email->print_debugger());
    }

}

这是一个工作的代码,我使用后,我解决了乌拉圭回合所面临的问题.....



文章来源: SMTP Gmail error with Codeigniter 2.1.3