php - 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.
请用适当的解决方案指导我。
解决方案
您的电子邮件配置应如下所示:
$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
推荐阅读
- javascript - 部署 Heroku 应用程序后 Nodemon 崩溃,错误:无效的 ELF 标头
- python - 循环数据集时 tf.function 中的异常执行顺序
- javascript - AG-Grid:基于子集的列分组
- unix - 根据多个选择标准打印
- azure-devops - 编辑 Azure DevOps 的 wiki 页面时自定义提交消息
- python - for 循环中 find() 的行为
- python - 为什么它会为 1 生成超出范围的索引错误?
- syntax - 逐元素求和和逐元素乘积之间的差异
- http-live-streaming - 在 hls 中,如何为客户端使用#EXT-X-DISCONTINUITY-SEQUENCE?
- c - 将数据从二维数组传递到结构