-
Notifications
You must be signed in to change notification settings - Fork 0
/
otp.php
45 lines (34 loc) · 1.16 KB
/
otp.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
// Function to generate OTP
function generateNumericOTP($n) {
// Take a generator string which consist of
// all numeric digits
$generator = "1357902468";
// Iterate for n-times and pick a single character
// from generator and append it to $result
// Login for generating a random character from generator
// ---generate a random number
// ---take modulus of same with length of generator (say i)
// ---append the character at place (i) from generator to result
$result = "";
for ($i = 1; $i <= $n; $i++) {
$result .= substr($generator, (rand()%(strlen($generator))), 1);
}
// Return result
return $result;
}
// Main program
$n = 4;
// print_r(generateNumericOTP($n));
$otp=generateNumericOTP($n);
$to_email = "[email protected]";
// here there will be name of email id to you wan to send
$subject = "Verification of Email address";
$body = "Your OTP is $otp";
$headers = "From: [email protected]";
if (mail($to_email, $subject, $body, $headers)) {
echo "Email successfully sent to $to_email... and otp is $otp";
} else {
echo "Email sending failed...";
}
?>