File: /var/www/grapossconnect/admin-dash/employee-birthday-mail.php
<?php
require_once("_dbconfig.php");
// $curDate = '12-24';
$curDate = date('m-d');
$employeeQry = $conn->query("SELECT `id`, `first_name`, `last_name`, `birth_date`, `email`, `phone_number`, `department`, `applying_position` FROM `grp_employees` where status='working' and DATE_FORMAT(birth_date, '%m-%d') = '$curDate' ORDER BY `id` ASC");
$allEmpployee = $conn->query("SELECT `email` FROM `grp_employees` where status='working' ORDER BY `id` ASC");
$addEmails = [
["email" => "shradha.khandelwal@grapossconnect.com"],
["email" => "ashu.sharma@grapossconnect.com"],
["email" => "rajiv.malik@grapossconnect.com"],
["email" => "info@sarkaripariksha.com"]
];
$empArr = [];
if ($allEmpployee->num_rows > 0) {
while ($row = $allEmpployee->fetch_assoc()) {
$empArr[] = ["email" => $row['email']];
}
}
$finalArray = array_merge($empArr, $addEmails);
// print_r($finalArray);
$conn->close();
$i = 1;
if ($employeeQry->num_rows > 0) {
foreach ($employeeQry as $emp) {
// echo "<br>" . $emp['first_name'] . "====" . $emp['last_name'] . "====" . $emp['birth_date'];
$name = $emp['first_name'] . " " . $emp['last_name'];
$dept = $emp['department'];
$posi = $emp['applying_position'];
$empEmail = $emp['email'];
foreach ($finalArray as $farr) {
$toEmailId = $farr['email'];
mailTemplate($name, $dept, $posi, $toEmailId);
}
}
}
function mailTemplate($name, $dept, $posi, $toEmail)
{
$subject = "Happy Birthday to " . $name . " !";
$mailContent = '
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>' . $subject . '</title>
</head>
<body style="margin: 0; font-family: Arial, sans-serif; background-color: #f9f4ef; color: #333;">
<section>
<div
style="max-width: fit-content; margin: 20px auto; background-color: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); text-align: center; background-image: url(https://grapossconnect.com/admin-dash/assets/img/birthday-bg.jpg);background-size: 100% 100%;background-repeat: no-repeat; padding: 8em 1em 1em;">
<div style=" padding: 20px;">
<img src="https://grapossconnect.com/admin-dash/assets/img/logo.png" alt="" style="width: 200px; margin-top: 20px;">
<div>
<h2 style="font-size: 18px; margin: 8px 0px; font-weight: 600; font-family: cursive;">Hi Team,</h2>
<p style="font-size: 15px; color: #555; font-weight: 600;">Lets wish a
Very Happy Birthday to our amazing colleague, <br>
<b style="color: #333333; font-size: 16px;">
' . $name . '
</b>,
from the <b>' . $dept . '</b> team!
</p>
<p style="font-size: 15px; color: #555; font-weight: 600;">
<b style="color: #333333; font-size: 16px;">
' . $name . '
</b>
is a valued member of our team and we appreciate their hard work, dedication and
positive attitude. Their contributions to the organisation are invaluable.
</p>
<p style="font-size: 15px; color: #555; font-weight: 600;">
Lets make today extra special for <b>' . $name . '</b> by showering them with birthday wishes!
Feel
free to drop a birthday message below.
</p>
</div>
<div>
<h3 style="font-size: 22px; font-family: cursive;">Happy Birthday</h3>
<p style="margin: 0px 0px 40px; font-size: 13px;">
<span>Best,</span><br>
<span>' . $name . '</span><br>
<span>' . $posi . '</span><br>
</p>
</div>
<a href=""></a>
</div>
</div>
</section>
</body>
</html>';
// echo $mailContent;
$fromname = "info@grapossconnect.com";
$replyto = "info@grapossconnect.com";
$email_id = $toEmail;
$source = "GC";
$data = array('fromname' => $fromname, 'replyto' => $replyto, 'title' => "Graposs Connect", 'subject' => $subject, 'content' => $mailContent, 'email_id' => $email_id, 'source' => $source);
// Data should be passed as json format
$data_json = json_encode($data);
// API URL to send data
$url = 'https://sp.gridlearn.com/vendorsData/apis/sendMail.php';
// curl initiate
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
// SET Method as a POST
curl_setopt($ch, CURLOPT_POST, 1);
// Pass user data in POST command
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Add the custom header
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-API-Origin: sarkaripariksha.com'
));
// Execute curl and assign returned data
$curlResponse = curl_exec($ch);
// Close curl
curl_close($ch);
$returnJson = json_decode($curlResponse);
}