How to use phpmailer, for example I have sent message to email address if user has registered successfully, then check email address, if email address exists stop sending email second time for registration. I have tried using phpmailer and php codes to send mail, every time when I checked if email address existed the program sent message to this email address, how to stop executing or stop sending message if user tries sign up and this email address exists
<?
include('data.php');
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';
if(isset($_POST["submit"])){
$email = trim(htmlspecialchars($_POST['email']));
if(filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)){
/*________________________________________________________________________*/
function EmailExists($conn, $email){
$s="SELECT * FROM dat WHERE email='$email'";
$res=mysqli_query($conn, $s);
$eml = mysqli_fetch_assoc($res);
return (is_array($eml) && count($eml)>0);
}
$emai=[];
if(EmailExists($conn, $email)):
$emai['has_error']=1;
$emai['response']="<script>alert('Email address is already exists')</script>";
endif;
/*________________________________________________________________________*/
$sql = "SELECT * FROM dat WHERE email = '$email'";
$rest = mysqli_query($conn, $sql);
$pres = mysqli_num_rows($rest);
if(!count($emai)){
} else {
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = ;
$mail->Username = 'test@gmail.com';
$mail->Password = 'test';
$mail->SMTPSecure = 'ssl';
$mail->Port = 443;
$mail->addAddress($_POST["email"]);
$mail->Subject="Registration was completed";
$mail->isHTML(FALSE);
$mail->Body="Welcome";
while($pres == 0){
switch($pres){
case $pres:
$mail->send();
break;
default:
break;
}
}
echo "<script>alert('Mail was sent successfully')</script>";
}
} else {
//echo "<script>alert('Wrong Email Address')</script>";
}
}
?>