like i said in the comments, store a key in session when you send a email, and then put a verification in this key before try to send any email
<?php
session_start(); //start a new sesion if you does not have one already
function sendEmail($mail,$empemail,$empname,$adminemail,$superevmail,$subject,$bodycontent,$bodycontent2){
//check if the session variable
if(isset($_SESSION['notified']) && !empty($_SESSION['notified']) && $_SESSION['notified'] == false) {
$mail->Encoding = 'base64';
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = '111'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
// Sender info
$mail->setFrom($empemail, $empname);
// $mail->addReplyTo('[email protected]', 'name');
// Add a recipient
$mail->addAddress($adminemail);//ad
$mail->addCC($superevmail);
//$mail->addBCC('[email protected]');
// Set email format to HTML
$mail->isHTML(true);
// Mail subject
$mail->Subject = $subject;
// Mail body content
$bodyContent = $bodycontent;
$bodyContent .=$bodycontent2;
$mail->Body = $bodyContent;
// Send email
if(!$mail->send()) {
echo 'Message could not be sent. Mailer Error: '.$mail->ErrorInfo;
} else {
//change the session variable
$_SESSION['notified'] = true;
echo 'Message has been sent.';
}
}
}
?>
See more in $_SESSION
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…