大家好我建立一个完整的注册系统,登录,登录,发送验证邮件等。我有一些问题如下:
我想查看电子邮件是否已存在于数据库中,但它没有给我任何错误消息,同样的电子邮件可以用来反复注册
我希望能够在用户成功注册后发送验证邮件,这就是我所得到的:
无法发送消息.Mailer错误:SMTP connect()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
注意问题2:lm遇到此问题,因为我没有改变:$ mail-> SMTPSecure ='????';和:$ mail-> Port = ????;
原因是我尚未设置域名和托管以便能够获取或修改这些信息,所以即时通讯使用个人电子邮件,那么我应该将什么用于SMTPSecure和$ mail->端口?。
两个问题的代码:
<?php
require_once('connect.php');
require_once('functions.php');
include('config.php');
// $error = ""; No need to declare this variable
if(isset($_POST) & !empty($_POST)){
//DEFINING FIELD INPUTS VARIABLES AND SECURING THE DATA
$firstname = mysqli_real_escape_string($connection, $_POST['fname']);
$verification_key = md5($firstname);
$lastname = mysqli_real_escape_string($connection, $_POST['lname']);
$email = mysqli_real_escape_string($connection, $_POST['email']);
$password =($_POST['password']);
$confirmpassword =($_POST['confirmpassword']);
//check email validation
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$error = "Veillez enter un courriel valide";
}
else if(strlen($password) < 8){
$error = "Mot de passe doit être au moins 8 characters";
}
else if($password !== $confirmpassword){
//CHECKING IF THE EMAIL ALREADY EXISTS IN THE DATABASE
$fmsg = "";
$emailsql = "SELECT * FROM users WHERE email='$email'";
$emailres = mysqli_query($connection, $emailsql);
$count = mysqli_num_rows($emailres);
if($count == 1){
$fmsg .= "Cet courriel existe deja, veuillez utiliser un autre!";
}
$error = "Mots de passe ne correspondent pas";
}
else{
//md5 encryption: password security
$password = md5($_POST['password']);
$confirmpassword = md5($_POST['confirmpassword']);
$sql = "INSERT INTO users (firstname, lastname, email, password, confirmpassword, verification_key) VALUES ('$firstname', '$lastname', '$email', '$password', '$confirmpassword', '$verification_key')";
$result = mysqli_query($connection, $sql);
if($result){
$smsg = "Enregistrement réussie";
// $id = mysqli_insert_id($connection);
//ADDING PHPMAILER TO SEND A VERIFICATION EMAIL once the user successfully registered
require 'PHPmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtphost';
$mail->SMTPAuth = true;
$mail->Username = 'smtpuser';
$mail->Password = 'smtppass';
$mail->SMTPSecure = 'tls'; // make sure to change the smtp secure to your security type (for example ssl)
$mail->Port = 587; // make sure to change the port number
$mail->setFrom('bafosth@yahoo.fr', 'Afro-1');
$mail->addAddress('bachwu@gmail.com', 'Bachir Amadou');
$mail->Subject = 'Verifiez votre courriel';
$mail->Body = "http://localhost/fost/verify.php?key=$verification_key&id=$id";
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}// end of script to the verification email
}
else{
$fmsg = "Enregistrement échoué";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="Montreal - User Reviews and Recommendations of Top Restaurants, Shopping, Nightlife, Entertainment, immigration lawyers, associations, web designers, Services and More at Afro-one">
<meta name="keywords" content="
Afro-one, recommendation, montreal, laval, quebec, ottawa, toronto, local, business, review, friend, restaurant, buffet, beauty salon, container shipping, shops, real estate agent, realtor, association, community, night-club, car dealer">
<meta name="author" content="Bachir Amadou Seydou">
<title>Afro-1</title>
<script src="./javascript/script.js"></script>
<link rel="stylesheet" type="text/css" href="./css/style.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<script src="https://cloud.tinymce.com/stable/tinymce.min.js"></script>
<script>tinymce.init({ selector:'textarea' });</script>
</head>
<body>
<div id="form-wrapper">
<div id="home">
<ul>
<li><a href="index.php">Accueil</a></li>
</ul>
</div>
<!--display the alert messages: success or failed-->
<?php if(isset($smsg)){ ?><div class="alert alert-success" role="alert"> <?php echo $smsg; ?> </div> <?php } ?>
<?php if(isset($fmsg)){ ?><div class="alert alert-danger" role="alert"> <?php echo $fmsg; ?> </div> <?php } ?>
<?php if(isset($error)){ ?><div class="alert alert-danger" role="alert"> <?php echo $error; ?> </div> <?php } ?>
<div id="menu">
<a href="signup.php">S'enregistrer</a>
<a href="login.php">Se connecter</a>
<a href="reset.php">Mot de passe oublié</a>
</div>
<div id="form-signup">
<form id="signup-form" name="sign-up" action="signup.php" method="POST">
<h1>Créez votre profile</h1>
<p>
<input type="text" name="fname" class="signup-input" required="required" placeholder="Prenom*" value="<?php if(isset($firstname) & !empty($firstname)) {echo $firstname; } ?>" >
</p>
<p>
<input type="text" name="lname" class="signup-input" required="required" placeholder="Nom*" value="<?php if(isset($lastname) & !empty($lastname)) {echo $lastname; } ?>" >
</p>
<p>
<input type="email" name="email" class="signup-input" required="required" placeholder="Courriel*" value="<?php if(isset($email) & !empty($email)) {echo $email; } ?>" >
</p>
<p>
<input type="password" name="password" class="signup-input" required="required" placeholder="Mot de passe*">
</p>
<p>
<input type="password" name="confirmpassword" class="signup-input" required="required" placeholder="Confirmez mot de passe*">
</p>
<p class="agree"> En vous inscrivant, vous acceptez <br>les<a href="condition.php"> Conditions d'utilisation</a><br> et la <a href="politic.php">Politique de confidentialité</a> d'Afro-1.
</p>
<p>
<input type="submit" class="signup-btn" name="btn-signup" value="Valider">
</p>
</div><!--END OF PHASE-1-->
</form> <!--END OF SIGN-UP-->
</div><!--END FO ALLFORM-->
</div><!--END OF FORM-WRAPPER-->
</body>
</html>