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();
}
- 2023-11-30 07:42:23 Connection: opening to smtp.gmail.com:25, timeout=300, options=array()
- 2023-11-30 07:42:23 Connection: opened
- 2023-11-30 07:42:23 SERVER -> CLIENT: 220-odin.idserverhost.com ESMTP Exim 4.96.2 #2 Thu, 30 Nov 2023 14:42:23 +0700 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
- 2023-11-30 07:42:23 CLIENT -> SERVER: EHLO wisata-rembangan.mifc.myhost.id
- 2023-11-30 07:42:23 SERVER -> CLIENT: 250-odin.idserverhost.com Hello wisata-rembangan.mifc.myhost.id [103.66.86.234]250-SIZE 52428800250-8BITMIME250-PIPELINING250-PIPECONNECT250-AUTH PLAIN LOGIN250-STARTTLS250 HELP
- 2023-11-30 07:42:23 CLIENT -> SERVER: STARTTLS
- 2023-11-30 07:42:23 SERVER -> CLIENT: 220 TLS go ahead
- 2023-11-30 07:42:23 Connection failed. Error #2: stream_socket_enable_crypto(): Peer certificate CN=`odin.idserverhost.com' did not match expected CN=`smtp.gmail.com' [/home/mifcmyho/wisata-rembangan.mifc.myhost.id/vendor/phpmailer/phpmailer/src/SMTP.php line 476]
- SMTP Error: Could not connect to SMTP host. Connection failed. stream_socket_enable_crypto(): Peer certificate CN=`odin.idserverhost.com' did not match expected CN=`smtp.gmail.com'
- 2023-11-30 07:42:23 CLIENT -> SERVER: QUIT
- 2023-11-30 07:42:23
- 2023-11-30 07:42:23
- 2023-11-30 07:42:23 Connection: closed
- SMTP Error: Could not connect to SMTP host. Connection failed. stream_socket_enable_crypto(): Peer certificate CN=`odin.idserverhost.com' did not match expected CN=`smtp.gmail.com'
from the provider say, nothing port is block. and my lecture said is from verison of my php mailer.
can someone tell me what a problem?
As the PHPMailer docs on this exact issue say, this will be because your hosting provider is redirecting your SMTP traffic to their own mail server, so what they are saying about not blocking is simply untrue. This is why when you ask to connect to
smtp.gmail.com
, you end up connected to something else, which is causing the certificate mismatch. This is exactly the kind of man-in-the-middle attack that TLS is designed to combat, and it's working exactly as it should by refusing to proceed.It also has nothing to do with your PHPMailer or PHP version.
To solve this, read the docs, but it's likely you'll need to alter your sending configuration to send through their mail servers (which will mean you can't send from a gmail address as that would be forgery that will be blocked by gmail's DMARC policy), or ask them to unblock the port properly.
Either that or find a better hosting provider.