【问题标题】:i'm trying to send emails using PHPmailer but i Get this error我正在尝试使用 PHPmailer 发送电子邮件,但我收到此错误
【发布时间】: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


【解决方案1】:

发生这种情况是因为您的加密模式和端口号组合错误。

您已设置:

$send->SMTPSecure = 'ssl';
$send->Port = 25;

SMTPSecuressl 模式是隐式 TLS(也称为 SMTPS),您连接的端口将期望您立即与 TLS 通信 - 但您连接的端口未配置为期望,所以它不起作用。

ssl 模式通常用于端口 465,但您可以改为切换到 STARTTLS 模式(显式 TLS),该模式将在 gmail 端口 587 上工作:

$send->SMTPSecure = 'tls';
$send->Port = 587;

This exact issue is described in great detail in the PHPMailer troubleshooting guide 链接到您的错误消息 - 当您遇到此类问题时,您应该始终做的第一件事就是阅读错误消息!

【讨论】:

    猜你喜欢
    • 2018-02-27
    • 2021-06-17
    • 2019-08-08
    • 2011-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-05
    • 1970-01-01
    相关资源
    最近更新 更多