CodeIgniter:流套接字启用加密 SSL/TLS 已为此流警告设置

Jon*_*n B 1 php email ssl codeigniter amazon-web-services

我得到一个PHP警告(stream_socket_enable_crypto(): SSL/TLS already set-up for this stream)当我发送邮件使用电子邮件笨电子邮件库从我的Ubuntu服务器12.04 LTS 的VirtualBox虚拟机通过我的AWS SES。尽管有警告,电子邮件还是成功发送

// /application/config/email.php:
$config['mailtype'] = 'html';
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://email-smtp.us-west-2.amazonaws.com';
$config['smtp_user'] = 'OMITTED';
$config['smtp_pass'] = 'OMITTED';
$config['smtp_port'] = 465;
$config['newline'] = "\r\n";
$config['wordwrap'] = true;
$config['smtp_crypto'] = 'tls';
Run Code Online (Sandbox Code Playgroud)

在这一点上,我发送电子邮件的代码没什么特别的:

$this->load->library('email');

$this->email->from('team@omitted.com', 'Team Omitted');
$this->email->to($person[0]['email']);
$this->email->subject('Temporary password');
$this->email->message('Here is your temporary password:<br />'.$new_pw);

if($this->email->send())
    $return['success'] = true;
else
    $return['err_msg'] = 'Failed to send password reset email. Please try again';
Run Code Online (Sandbox Code Playgroud)

警告究竟是什么告诉我的,我该如何解决这个问题?提前谢谢!

小智 5

这解决了在 CodeIgniter 中尝试将 SSL/TLS smtp 加密与电子邮件库一起使用时的警告。

打开文件:/system/libraries/Email.php

然后,进入 _smtp_connect() 函数,您将在代码上按如下方式对其进行编辑:

if ($this->smtp_crypto == 'tls')
{
    $this->_send_command('hello');
    $this->_send_command('starttls');
    if( strpos( $this->smtp_host, 'ssl://') === FALSE ) {
      stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT);
    }
}
Run Code Online (Sandbox Code Playgroud)

有关函数 stream_socket_enable_crypto 的更多信息:http : //php.net/manual/en/function.stream-socket-enable-crypto.php