php - 为什么不使用 PHPMailer 发送电子邮件?
问题描述
有谁知道我在这里的代码哪里出错了?可能是因为我使用本地主机发送?或者是其他东西?
当我单击带有不正确电子邮件的重置密码按钮时,会出现消息,但是当我输入正确的电子邮件时,什么也没有显示,也没有发送电子邮件。使用 hotmail 发送电子邮件,更改了电子邮件帐户上的 IMAP 设置。
PHP:
include_once(ROOT_PATH . "/app/database/db.php");
use PHPMailer\PHPMailer\PHPMailer;
if(isset($_POST['email'])) {
global $conn;
$email = $_POST['email'];
$sql = $conn->query("SELECT u_id FROM users WHERE email='$email'");
if ($sql->num_rows > 0) {
$token = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuioplkjhgfdsazxcvbnm1234567890£$%&?@!#";
$token = str_shuffle($token);
$token = substr($token, 0 , 20);
$conn->query("UPDATE users SET token='$token',
tokenExpire=DATE_ADD(NOW(), INTERVAL 5 MINUTE)
WHERE email='$email'");
require_once(ROOT_PATH . "/app/includes/phpmailer/PHPMailer.php");
require_once(ROOT_PATH . "/app/includes/phpmailer/Exception.php");
$mail = new PHPMailer();
$mail->SMPTDebug = 3;
$mail->Host = "";
$mail->SMPTAuth = true;
$mail->Username = "********";
$mail->Password = "********";
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->addAddress($email);
$mail->From("********");
$mail->FromName = "Cath";
$mail->Subject = "Reset Password";
$mail->isHTML(true);
$mail->smtpConnect(
array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
"allow_self_signed" => true
)
)
);
$mail->Body = "
Hi,<br><br>
In order to reset your password, please click on the link below:<br>
<a href='
http://localhost/weinspire/blog/resetPassword.php?email=$email&token=$token
'>http://localhost/weinspire/blog/resetPassword.php?email=$email&token=$token</a><br><br>
Thanks,<br><br>
Seeing The New
";
if($mail->send())
exit(json_encode(array("status" => 1, "msg" => 'Please check your email inbox.')));
else
exit(json_encode(array("status" => 0, "msg" => 'Something has gone wrong.')));
} else
exit(json_encode(array("status" => 0, "msg" => 'Please check your inputs.')));
}
HTML:
<div class="fp-container">
<h1 class="top-banner">Forgotten Password</h1>
<h2>Forgotten your password?</h2>
<h3>Don't worry - simply type in your email address, click <span class="btn">reset password</span> and we'll send you an email to reset your password.</h3>
<div class="fp-form">
<input id="email" type="text" name="email" placeholder="Email">
<button class="btn reset-btn" type="submit" name="button">Reset Password</button>
<br><br>
<p id="response"></p>
</div>
</div>
谢谢你的帮助。
解决方案
推荐阅读
- php - Laravel Nova 将原始文件名存储在数据库和本地存储中
- delphi - 用于 FMX 的 TOpenPictureDialog?
- typescript - 如何访问组件外部“设置”功能中定义的属性?
- java - 通过安卓版本兼容下载PDF
- reactjs - React Router - 不同页面上的不同链接
- java - 标记行在 vaadin 网格中单击鼠标时选中(SelectionMode.MULTI)
- python - 如何将值传递给 .toml 文件中的键?
- azure-data-factory - Datafactory:将获取数据活动结构输出写入数据湖
- python - 熊猫时间序列数据框中的“SettingwithCopyWarning”
- python - SQLAlchemy 返回一个结果双精度 - 即使只有一个预期