每次我单击android中的按钮时,它都会两次向收件人发送邮件。因此,此电子邮件发送是在我请求重新发送验证码以进行电子邮件注册时。当我单击重新发送验证按钮时,我收到的电子邮件带有一个随机生成的字符串($ code),然后几秒钟后,我收到了同一封电子邮件,但区别在于随机生成的字符串($ code)。
<head>
<meta charset="utf-8">
<title>Gmaps</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<script src="https://maps.googleapis.com/maps/api/js?key=key&libraries=visualization"></script>
</head>
已编辑:
这是我完整的resendCode.php代码。我提供了一种方法来检查脚本是否使用$ count ++运行了两次,但是来自android的日志
不。使用脚本的时间:1
以下是android代码段。 CodeVerification.java。我也尝试检查方法codeReset();通过增加计数被两次调用。日志显示
08-03 22:32:09.195 6702-7690 / com.example.joshua.itproj2 D /计数:计数:1
08-03 22:32:11.760 6702-7690 / com.example.joshua.itproj2 D /计数:计数:1
<?php
require_once 'connect.php';
header('Content-Type: application/json');
require_once 'PHPMailer/PHPMailerAutoload.php';
date_default_timezone_set('Asia/Manila');
if($_SERVER["REQUEST_METHOD"] == 'POST')
{
$Email = $_POST['Email'];
$actionType = $_POST['actionType'];
$count = 0;
$random_string = substr(str_shuffle(str_repeat("0123456789abcdefghijklmnopqrstuvwxyz", 6)), 0, 6);
$verification_code = $random_string;
$verificationQuery = "SELECT * FROM email_verification WHERE email='$Email'";
$verificationResults = mysqli_query($conn, $verificationQuery);
$result = array();
if($actionType == 'Resend')
{
if(mysqli_num_rows($verificationResults)===1)
{
$updateCode = "UPDATE email_verification SET verification_code = '$verification_code' WHERE email='$Email'";
if(mysqli_query($conn, $updateCode))
{
$result["success"]="1";
$result["message"]="Verification Code Sent";
echo json_encode($result);
sendingEmail($Email, $verification_code, $count);
}
else
{
$result["success"]="0";
$result["message"]="Verification Code Not Sent";
echo json_encode($result);
}
}
}
else
{
$result["success"]="0";
$result["message"]="Verification Code Not Sent";
echo json_encode($result);
}
mysqli_close($conn);
}
function sendingEmail($emailSent, $code)
{
$mail = new PHPMailer(true); // Passing `true` enables exceptions
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'tls://smtp.hostinger.ph'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'developers.itproj2@itproj2captcha.xyz'; // SMTP username
$mail->Password = '*************'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('developers.itproj2@itproj2captcha.xyz', 'Developer @ITPROJ2');
$mail->addAddress($emailSent, ''); // Add a recipient
$mail->addReplyTo('developers.itproj2@itproj2captcha.xyz', 'Email Verification');
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Email Verification';
$mail->Body = 'Hi, <br><br>This is your verification code for your
email <b>'.$code.'</b><br><br>Thanks,<br>Group CAPTCHA ';
$status = $mail->Send();
$count++;
echo "No. of times script was used: " . $count;
if ($status)
{
echo 'Message has been sent.';
}
else
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
}
?>