繁体   English   中英

我正在尝试使用 PHPmailer 发送电子邮件,但我收到此错误

[英]i'm trying to send emails using PHPmailer but i Get this error

我得到这个错误

2020-06-03 21:08:07 Connection: opening to ssl://smtp.gmail.com:25, timeout=300, options=array() 2020-06-03 21:08:07 Connection failed.

错误 #2:stream_socket_client(): SSL 操作失败,代码为 1。

OpenSSL Error messages:error:1408F10B:SSL routines:ssl3_get_record:wrong version number [C:\xampp\htdocs\Go\vendor\phpmailer\phpmailer\src\SMTP.php line 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 连接失败。 Error #2: stream_socket_client(): unable to connect to ssl://smtp.gmail.com:25 (Unknown error) [C:\xampp\htdocs\Go\vendor\phpmailer\phpmailer\src\SMTP.php line 344 ]

2020-06-03 21:08:07 SMTP 错误:无法连接到服务器:(0)SMTP 连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

无法发送消息。Mailer 错误: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';
}

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

您已设置:

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

sslSMTPSecure模式是隐式 TLS(也称为 SMTPS),您连接到的端口将期望您立即与 TLS 通信 - 但您正在连接到未配置为期望的端口,因此它不会工作。

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

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

这个确切的问题在 PHPMailer 故障排除指南中详细描述了与您链接的错误消息 - 当您遇到此类问题时,您应该始终做的第一件事就是阅读错误消息!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM