use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
//Load Composer's autoloader
require 'vendor/autoload.php';
function send_password_reset($get_name, $get_email, $token)
{
$mail = new PHPMailer(true);
$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '';
$mail->Password = '';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('[email protected]','E-TICKETING REMBANGAN');
$mail->addAddress($get_email);
$mail->isHTML(true);
$mail->Subject = 'Reset Password Notification';
$email_template = "
<html>
<head>
<style>
.button {
display: inline-block;
padding: 10px 20px;
text-align: center;
text-decoration: none;
background-color: #4CAF50;
color: white;
border-radius: 10px;
margin: auto;
display: block;
width: 200px;
text-decoration: none; /* Removes underline */
color: white; /* Makes text color white */
}
.button-container {
text-align: center;
}
</style>
</head>
<body>
<h2>Anda menerima email karena kami mendapatkan permintaan Pembaharuan password untuk akun anda pada laman <b>Wisata Rembangan</b></h2>
<h5>Jangan bagikan link ini kepada siapapun, abaikan email ini jika bukan ada yang meminta perubahan password!</h5>
<div class='button-container'>
<a href='https://wisata-rembangan.mifc.myhost.id/password-change.php?token=$token&email=$get_email' class='button'>Klik Disini</a>
</div>
</body>
</html>";
$mail->Body = $email_template;
$mail->send();
}
根据提供商的说法,没有任何端口被阻止。我的讲座说的是我的 php 邮件程序的版本。
有人可以告诉我出了什么问题吗?
此错误表明 odin.idserverhost.com 提供的服务器证书与 smtp.gmail.com 的预期证书不匹配。 SSL/TLS 协商失败,因为您要连接的服务器 (odin.idserverhost.com) 不是预期的 SMTP 服务器 (smtp.gmail.com)。
以下是您可以检查或考虑的一些事项:
正确的 SMTP 服务器设置: 确保您使用的 Gmail SMTP 服务器设置正确。 Gmail 的 SMTP 和 SSL 的正确服务器是端口 465 上的 smtp.gmail.com。
验证主机名: 仔细检查您用于 SMTP 连接的主机名。它应该是 smtp.gmail.com,而不是 odin.idserverhost.com。该错误表明您要连接的服务器具有颁发给 odin.idserverhost.com 的证书,这与预期的 smtp.gmail.com 不匹配。
使用 TLS 而不是 SSL: 您可能想尝试使用 TLS,而不是使用 SSL。对于 Gmail,您应该使用 TLS 连接到端口 587。这可以在您的邮件配置中设置。
检查服务器证书: 确保 odin.idserverhost.com 的证书有效且在您的服务器上配置正确。如果证书有任何问题,可能会导致 SSL/TLS 协商失败。
防火墙和网络问题: 检查是否有任何防火墙或网络问题阻止您的服务器在所需端口上连接到 smtp.gmail.com。
调试工具: 您可以使用 OpenSSL 等工具来调试 SSL/TLS 连接并检查证书。这可以帮助您识别 SSL/TLS 握手的任何问题。
请记住避免在代码中硬编码特定服务器信息,并使用配置文件或环境变量以获得灵活性。
通过解决这些问题,您应该能够排除并解决 SMTP 连接问题。如果问题仍然存在,您可能需要联系您的托管提供商或系统管理员寻求帮助。