我正在研究netbeans,winsows和xampp。我相信这与PHPMailer的版本有关,我看到了带有
的示例PHPAutoload.php
但是使用我从gitHub下载的版本,我看不到该文件。一切看起来不错,它确实插入了数据库,但是到了代码的这一部分
$msg = "Something wrong happened! Please try again!";
我将PHPMailer文件夹粘贴到c:/ xampp / htdocs / pojectmail / PHPMailer中。
这是我的register.php代码
<?php
$msg = "";
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
if (isset($_POST['submit'])) {
$con = new mysqli('localhost', 'root', '', 'research_phpEmailConfirmation');
$name = $con->real_escape_string($_POST['name']);
$email = $con->real_escape_string($_POST['email']);
$password = $con->real_escape_string($_POST['password']);
$cPassword = $con->real_escape_string($_POST['cPassword']);
if ($name == "" || $email == "" || $password != $cPassword)
$msg = "Please check your inputs!";
else {
$sql = $con->query("SELECT id FROM users WHERE email='$email'");
if ($sql->num_rows > 0) {
$msg = "Email already exists in the database!";
} else {
$token = 'qwertzuiopasdfghjklyxcvbnmQWERTZUIOPASDFGHJKLYXCVBNM0123456789!$/()*';
$token = str_shuffle($token);
$token = substr($token, 0, 10);
$hashedPassword = password_hash($password, PASSWORD_BCRYPT);
$con->query("INSERT INTO users (name,email,password,isEmailConfirmed,token)
VALUES ('$name', '$email', '$hashedPassword', '0', '$token');
");
include_once "PHPMailer/PHPMailer.php";
include_once "PHPMailer/Exception.php";
$mail = new PHPMailer();
$mail->setFrom('hello@codingpassiveincome.com');
$mail->addAddress($email, $name);
$mail->Subject = "Please verify email!";
$mail->isHTML(true);
$mail->Body = "aa";
if ($mail->send()) {
$msg = "You have been registered! Please verify your email!";
} else {
$msg = "Something wrong happened! Please try again!";
}
}
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Register</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
</head>
<body>
<div class="container" style="margin-top: 100px;">
<div class="row justify-content-center">
<div class="col-md-6 col-md-offset-3" align="center">
<img src="images/logo.png"><br><br>
<?php if ($msg != "") echo $msg . "<br><br>" ?>
<form method="post" action="register.php">
<input class="form-control" name="name" placeholder="Name..."><br>
<input class="form-control" name="email" type="email" placeholder="Email..."><br>
<input class="form-control" name="password" type="password" placeholder="Password..."><br>
<input class="form-control" name="cPassword" type="password" placeholder="Confirm Password..."><br>
<input class="btn btn-primary" type="submit" name="submit" value="Register">
</form>
</div>
</div>
</div>
</body>
</html>