forked from IT-DEPT-ASPL/HRMS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddmail.php
More file actions
95 lines (78 loc) · 2.49 KB
/
addmail.php
File metadata and controls
95 lines (78 loc) · 2.49 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
$servername = "localhost";
$username = "Anika12";
$password = "Anika12";
$dbname = "ems";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = $_POST['email'];
$purpose = $_POST['purpose'];
$to = $_POST['email'];
function generateRandomString($length = 10)
{
return substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);
}
function emailExists($email)
{
global $conn;
$email = mysqli_real_escape_string($conn, $email);
$query = "SELECT COUNT(*) as count FROM emp WHERE empemail = '$email'";
$result = $conn->query($query);
if ($result) {
$row = $result->fetch_assoc();
return $row['count'] > 0;
} else {
return false;
}
}
function emailExists1($email)
{
global $conn;
$email = mysqli_real_escape_string($conn, $email);
$query = "SELECT COUNT(*) as count FROM onb WHERE empemail = '$email'";
$result = $conn->query($query);
if ($result) {
$row = $result->fetch_assoc();
return $row['count'] > 0;
} else {
return false;
}
}
if (emailExists($email)) {
echo "exists";
exit();
}
if (emailExists1($email)) {
echo "exist";
exit();
}
$uniqueLink = generateRandomString();
$queryParams = http_build_query(['email' => $email, 'token' => $uniqueLink]);
$url = "https://hrms.anikasterilis.com/add-email.php?" . $queryParams;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$msg = curl_exec($ch);
curl_close($ch);
$subject = 'Welcome to the ASPL - Onboarding Process Initiated';
$from_email = '[email protected]';
$from_name = 'ASPL HRMS';
$headers = "From: $from_name <$from_email>\r\n" .
"Reply-To: $from_email\r\n" .
"Content-type: text/html\r\n" .
'X-Mailer: PHP/' . phpversion();
if (mail($to, $subject, $msg, $headers)) {
$query = "INSERT INTO mail_log (email, purpose) VALUES ('$email', '$purpose')";
if ($conn->query($query) === TRUE) {
echo "";
} else {
echo "Error: " . $conn->error;
}
} else {
echo "Error occur";
}
$conn->close();
}