首页 > 解决方案 > codeigniter 显示 stream_socket_client(): Failed to enable crypto 这个错误在 sendmail 上?

问题描述

我正在尝试在我的本地机器上使用 xampp 服务器发送带有代码点火器的电子邮件,但它不起作用。它向我展示了一些我在网上搜索过的错误,但我现在很无助,我尝试过的所有解决方案都对我失败了。

以下是我的 3 个错误:

Message: stream_socket_client(): SSL: The operation completed successfully.

Message: stream_socket_client(): Failed to enable crypto

Message: stream_socket_client(): unable to connect to ssl://smtp.gmail.com:587 (Unknown error)

这是我的 php 代码:

$config = Array(
        'protocol'  => 'smtp',
        'smtp_host' => 'ssl://smtp.gmail.com',
        'smtp_port' => '587',
        'smtp_user' => 'mygmailid@gmail.com',
        'smtp_pass' => 'xxxmypassword',
        'mailtype'  => 'html',
        'starttls'  => true,
        'newline'   => "\r\n"
                    );
        $message = '';
        $this->load->library('email', $config);
        $this->email->set_newline("\r\n");
        $this->email->initialize($config);
        $this->email->from('mygmailid@gmail.com');
        $this->email->to('mygmailid@gmail.com');
        $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());
        }

在 print_debugger 我也得到这个错误:

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

This is a multi-part message in MIME format. Your email application may not support this format.

请用适当的解决方案指导我。

标签: phpcodeignitersendmail

解决方案


您的电子邮件配置应如下所示:

$config = Array(
  'protocol'  => 'smtp',
  'smtp_host' => 'ssl://smtp.gmail.com',
  'smtp_port' => 465,
  'smtp_user' => 'YOUR_USERNAME',
  'smtp_pass' => 'YOUR_PASSWORD',
  'mailtype'  => 'html',
  'charset'   => 'utf-8',
  'newline'   => "\r\n",
  'wordwrap'  => TRUE,
);

就像 Sandeep J Patel 在他的评论中所说的那样,您还需要在您的 gmail 帐户设置中启用对不太安全的应用程序的访问。

请参阅他们的帮助页面:https ://support.google.com/accounts/answer/6010255?hl=en


推荐阅读