【发布时间】:2020-06-03 21:14:25
【问题描述】:
我得到这个错误
2020-06-03 21:08:07 连接:打开到 ssl://smtp.gmail.com:25, timeout=300, options=array() 2020-06-03 21:08:07 连接失败。
错误 #2:stream_socket_client():SSL 操作失败,代码为 1。
OpenSSL 错误消息:错误:1408F10B:SSL 例程:ssl3_get_record:版本号错误 [C:\xampp\htdocs\Go\vendor\phpmailer\phpmailer\src\SMTP.php 第 344 行]
2020-06-03 21:08:07 连接失败。错误 #2:stream_socket_client(): 无法启用加密 [C:\xampp\htdocs\Go\vendor\phpmailer\phpmailer\src\SMTP.php 第 344 行]
2020-06-03 21:08:07 连接失败。错误 #2:stream_socket_client():无法连接到 ssl://smtp.gmail.com:25(未知错误)[C:\xampp\htdocs\Go\vendor\phpmailer\phpmailer\src\SMTP.php 第 344 行]
2020-06-03 21:08:07 SMTP 错误:无法连接到服务器:(0) SMTP 连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
无法发送邮件。邮件程序错误:SMTP 连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
<?php
require './vendor/autoload.php';
$send = new PHPMailer\PHPMailer\PHPMailer();
$send->SMTPDebug = 4;// Enable verbose debug output
$send->isSMTP(); // Set mailer to use SMTP
$send->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$send->SMTPAuth = true; // Enable SMTP authentication
$send->Username = 'abdelkbirkh2@gmail.com'; // SMTP username
$send->Password = 'µµµµµµ'; // SMTP password
$send->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$send->Port = 25; // TCP port to connect to
$send->setFrom('abdelkbirk@gmail.com', 'Mailer');
$send->addAddress('abdo9@gmail.com', 'Joe User'); // Add a recipient
$send->addAddress('abdok79@gmail.com'); // Name is optional
$send->addReplyTo('abdelk2@gmail.com', 'Information');
$send->addCC('abdelkbir32@gmail.com');
$send->addBCC('abdelkbirk32@gmail.com');
// $send->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
// $send->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$send->isHTML(true); // Set email format to HTML
$send->Subject = 'Here is the subject';
$send->Body = 'This is the HTML message body <b>in bold!</b>';
$send->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$send->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $send->ErrorInfo;
} else {
echo 'Message has been sent';
}
【问题讨论】:
-
基本上您的安装不支持所需的加密功能。我会按照错误消息中链接的故障排除指南进行操作。
标签: php windows xampp phpmailer