当我在本地服务器上运行此代码时,运行成功。 但是当我使用000webhost.com在我的肝脏服务器帐户上上传此代码时 显示此错误消息无法发送。邮件错误:SMTP错误:无法验证
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
require '../../config.php';
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
if(isset($_POST['reset-password'])){
$emailTo = $_POST['email'];
$code = uniqid(true);
$query ="INSERT INTO resetpassword(code,email) VALUES('$code', '$emailTo')";
$result = mysqli_query($con, $query);
if(!$query){
echo $query;
exit("Internal Server Error Please Try Again Some Time");
}
//Server settings
$mail->SMTPDebug = 2;
$mail = new PHPMailer(true);
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'myemail@gmail.com'; // SMTP username
$mail->Password = '***********'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
$mail->SMTPSecure = 'ssl';
$mail->Port = 465; // TCP port to connect to
//Recipients
$mail->setFrom('myemail@gmail.com', 'Mycityasind');
$mail->addAddress($emailTo, 'Mahendra Singh'); // Add a recipient
$mail->addReplyTo('myemail@gmail.com', 'Information');
// $mail->addCC('cc@example.com');
// $mail->addBCC('bcc@example.com');
// Attachments
// $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
// Content
$url="http://". $_SERVER["HTTP_HOST"]. dirname($_SERVER["PHP_SELF"]). "/resetpassword.php?code=$code";
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Reset Your Password';
$mail->Body = "<h1>Hello Sir,<h1><br>
<h2>Just we received a request for reset your password.
Please Click on <a href='$url'>this link</a> and reset your store password</h2> $code";
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
header("../login.php");
}
catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
exit();
}
我也添加了此代码。
try {
$PHPMailer->SMTPOptions = array (
'ssl' => array (
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
在堆栈上读取并添加这些行
$mailer = new PHPMailer(true);
$mailer->SMTPSecure = 'ssl'; // instead of tls
还将端口更改为
$mail->Port = 587;
但不能解决此问题 请帮助谢谢