implement email send
This commit is contained in:
@@ -51,6 +51,7 @@
|
|||||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
// var_dump($rows);
|
// var_dump($rows);
|
||||||
foreach($rows as $row){
|
foreach($rows as $row){
|
||||||
|
$usersEmailForSendMessage = $row['email'];
|
||||||
$usersNameforSendMessage = $row['name'];
|
$usersNameforSendMessage = $row['name'];
|
||||||
$usersNumberforSendMessage = $row['phone'];
|
$usersNumberforSendMessage = $row['phone'];
|
||||||
$nameParts = explode(" ", $row['name']);
|
$nameParts = explode(" ", $row['name']);
|
||||||
@@ -272,6 +273,130 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
<?php
|
||||||
|
if (isset($_GET['send-email-id']) && $_GET['send-email-id']) {
|
||||||
|
$url = "https://api.brevo.com/v3/smtp/email";
|
||||||
|
$apiKey = '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';
|
||||||
|
$data = [
|
||||||
|
"to" => [
|
||||||
|
[
|
||||||
|
"email" => $usersEmailForSendMessage,
|
||||||
|
"name" => $usersNameforSendMessage
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"templateId" => (int)$_GET['send-email-id'], // Ensure this is an integer
|
||||||
|
"batchId" => "5c6cfa04-eed9-42c2-8b5c-6d470d978e9d"
|
||||||
|
];
|
||||||
|
$jsonData = json_encode($data);
|
||||||
|
|
||||||
|
$options = [
|
||||||
|
'http' => [
|
||||||
|
'header' => "Content-Type: application/json\r\n" .
|
||||||
|
"api-key: $apiKey\r\n",
|
||||||
|
'method' => 'POST',
|
||||||
|
'content' => $jsonData,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$context = stream_context_create($options);
|
||||||
|
$fp = @fopen($url, 'r', false, $context); // Suppress warnings to handle them manually
|
||||||
|
|
||||||
|
if ($fp === FALSE) {
|
||||||
|
$error = error_get_last();
|
||||||
|
echo 'Error occurred: ' . $error['message'];
|
||||||
|
} else {
|
||||||
|
$response = stream_get_contents($fp);
|
||||||
|
$http_response_header = $http_response_header ?? [];
|
||||||
|
$response_code = (int)substr($http_response_header[0], 9, 3);
|
||||||
|
|
||||||
|
if ($response === FALSE || $response_code >= 400) {
|
||||||
|
echo 'Error reading response: ' . $response;
|
||||||
|
} else {
|
||||||
|
$templateName = $_GET['send-email-id'];
|
||||||
|
$messageMethod = 'Email';
|
||||||
|
try {
|
||||||
|
$stmt = $conn->prepare("INSERT INTO communication (leadid, useremail, username, templateid, method) VALUES (:leadid, :useremail, :username, :templateid, :method)");
|
||||||
|
$stmt->bindParam(':leadid', $_GET['id']);
|
||||||
|
$stmt->bindParam(':useremail', $_SESSION['email']);
|
||||||
|
$stmt->bindParam(':username', $_SESSION['name']);
|
||||||
|
$stmt->bindParam(':templateid', $templateName);
|
||||||
|
$stmt->bindParam(':method', $messageMethod);
|
||||||
|
$stmt->execute();
|
||||||
|
$sendSuccessMessage = "Email Sent successfully";
|
||||||
|
echo '<script>window.location.href = "/edit-lead/?id='.$_GET['id'].'"</script>';
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
echo "Error: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Close the file pointer
|
||||||
|
fclose($fp);
|
||||||
|
}
|
||||||
|
} elseif (isset($_GET['send-whatsapp-id']) && $_GET['send-whatsapp-id']) {
|
||||||
|
$url = "https://api.interakt.ai/v1/public/message/";
|
||||||
|
$apiKey = 'Basic {{OTgyajd4bHFUSXItSW9PN1BTdzhOenNDaS0ya0NQeXByRE0tMnRyQ3FrUTo=}}';
|
||||||
|
$data = [
|
||||||
|
"fullPhoneNumber" => $usersNumberforSendMessage,
|
||||||
|
"callbackData" => "some text here",
|
||||||
|
"type" => "Template",
|
||||||
|
"template" => [
|
||||||
|
"name" => "boost_conversion",
|
||||||
|
"languageCode" => "en",
|
||||||
|
"headerValues" => [
|
||||||
|
"header_variable_value"
|
||||||
|
],
|
||||||
|
"bodyValues" => [
|
||||||
|
$usersNameforSendMessage
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
$jsonData = json_encode($data);
|
||||||
|
|
||||||
|
$options = [
|
||||||
|
'http' => [
|
||||||
|
'header' => "Content-Type: application/json\r\n" .
|
||||||
|
"Authorization: $apiKey\r\n" .
|
||||||
|
"Content-Length: " . strlen($jsonData) . "\r\n",
|
||||||
|
'method' => 'POST',
|
||||||
|
'content' => $jsonData,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$context = stream_context_create($options);
|
||||||
|
$fp = fopen($url, 'r', false, $context);
|
||||||
|
if ($fp === FALSE) {
|
||||||
|
echo 'Error occurred';
|
||||||
|
} else {
|
||||||
|
$response = stream_get_contents($fp);
|
||||||
|
|
||||||
|
if ($response === FALSE) {
|
||||||
|
echo 'Error reading response';
|
||||||
|
} else {
|
||||||
|
if(isset($_GET['send-whatsapp-id'])){
|
||||||
|
$templateName = $_GET['send-whatsapp-id'];
|
||||||
|
} elseif(isset($_GET['send-email-id'])){
|
||||||
|
$templateName = $_GET['send-email-id'];
|
||||||
|
}
|
||||||
|
$messageMethod = 'WhatsApp';
|
||||||
|
try {
|
||||||
|
$stmt = $conn->prepare("INSERT INTO communication (leadid, useremail, username, templateid, method) VALUES (:leadid, :useremail, :username, :templateid, :method)");
|
||||||
|
$stmt->bindParam(':leadid', $_GET['id']);
|
||||||
|
$stmt->bindParam(':useremail', $_SESSION['email']);
|
||||||
|
$stmt->bindParam(':username', $_SESSION['name']);
|
||||||
|
$stmt->bindParam(':templateid', $templateName);
|
||||||
|
$stmt->bindParam(':method', $messageMethod);
|
||||||
|
$stmt->execute();
|
||||||
|
$sendSuccessMessage = "WhatsApp Sent successfully";
|
||||||
|
echo '<script>window.location.href = "/edit-lead/?id='.$_GET['id'].'"</script>';
|
||||||
|
} catch(PDOException $e) {
|
||||||
|
echo "Error: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
// echo '<script>window.location.href="/edit-lead/?id='.$_GET['id'].'"</script>';
|
||||||
|
// echo $response;
|
||||||
|
}
|
||||||
|
fclose($fp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
<div class="flex flex-col div-custom-margin" style="width: 100%;" >
|
<div class="flex flex-col div-custom-margin" style="width: 100%;" >
|
||||||
<div class="bg-[#F6F6F6] rounded-xl p-3">
|
<div class="bg-[#F6F6F6] rounded-xl p-3">
|
||||||
<div class="flex-container-x2y place-content-between" style="border-bottom: 2px solid #7E8299; border-style: dashed; padding-bottom: 3px;">
|
<div class="flex-container-x2y place-content-between" style="border-bottom: 2px solid #7E8299; border-style: dashed; padding-bottom: 3px;">
|
||||||
@@ -495,13 +620,18 @@
|
|||||||
foreach ($appt_data as $appt) {
|
foreach ($appt_data as $appt) {
|
||||||
// Assuming 'comment' and 'date' fields are in the appointments table
|
// Assuming 'comment' and 'date' fields are in the appointments table
|
||||||
$apptDate = explode(' ', $appt['time']); // Split date and time
|
$apptDate = explode(' ', $appt['time']); // Split date and time
|
||||||
|
if (is_numeric($appt['templateid'])) {
|
||||||
|
$templateNameForPrint = 'Email Template ID ' . $appt['templateid'];
|
||||||
|
} else {
|
||||||
|
$templateNameForPrint = $appt['templateid'];
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<div class="flex flex-col px-6" style="border-bottom: 2px solid #D9D9D9;">
|
<div class="flex flex-col px-6" style="border-bottom: 2px solid #D9D9D9;">
|
||||||
<div class="flex flex-row place-content-between align-items-center">
|
<div class="flex flex-row place-content-between align-items-center">
|
||||||
<p style="font-size: 15px; font-weight: bold;"><?php echo $appt['templateid']; ?></p>
|
<p style="font-size: 15px; font-weight: bold;"><?php echo $templateNameForPrint; ?></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="grid grid-cols-2">
|
<div class="grid grid-cols-2">
|
||||||
<p class="text-[#7E8299] ">Mail Send by <?php echo $appt['username']; ?></p>
|
<p class="text-[#7E8299] "><?php echo $appt['method']; ?> Send by <?php echo $appt['username']; ?></p>
|
||||||
<div class="flex flex-col" style="border-left: 3px solid #7875F4;">
|
<div class="flex flex-col" style="border-left: 3px solid #7875F4;">
|
||||||
<p style="font-weight: bold; padding-left: 6px;"><?php echo $apptDate[0]; ?></p>
|
<p style="font-weight: bold; padding-left: 6px;"><?php echo $apptDate[0]; ?></p>
|
||||||
<p style="padding-left: 6px;"><?php echo $apptDate[1]; ?></p>
|
<p style="padding-left: 6px;"><?php echo $apptDate[1]; ?></p>
|
||||||
@@ -543,81 +673,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<p><?php if(isset($sendSuccessMessage)){echo $sendSuccessMessage;} ?></p>
|
||||||
if(isset($_GET['send-whatsapp-id']) && $_GET['send-whatsapp-id']){
|
|
||||||
$templateID = $_GET['send-whatsapp-id'];
|
|
||||||
$usersNumberforSendMessagex = '917001601485';
|
|
||||||
// echo $usersNameforSendMessage;
|
|
||||||
// $usersNames = $usersNameforSendMessage;
|
|
||||||
|
|
||||||
$url = "https://api.interakt.ai/v1/public/message/";
|
|
||||||
$apiKey = 'Basic {{OTgyajd4bHFUSXItSW9PN1BTdzhOenNDaS0ya0NQeXByRE0tMnRyQ3FrUTo=}}';
|
|
||||||
$data = [
|
|
||||||
"fullPhoneNumber" => $usersNumberforSendMessagex,
|
|
||||||
"callbackData" => "some text here",
|
|
||||||
"type" => "Template",
|
|
||||||
"template" => [
|
|
||||||
"name" => "boost_conversion",
|
|
||||||
"languageCode" => "en",
|
|
||||||
"headerValues" => [
|
|
||||||
"header_variable_value"
|
|
||||||
],
|
|
||||||
"bodyValues" => [
|
|
||||||
$usersNameforSendMessage
|
|
||||||
]
|
|
||||||
]
|
|
||||||
];
|
|
||||||
$jsonData = json_encode($data);
|
|
||||||
|
|
||||||
$options = [
|
|
||||||
'http' => [
|
|
||||||
'header' => "Content-Type: application/json\r\n" .
|
|
||||||
"Authorization: $apiKey\r\n" .
|
|
||||||
"Content-Length: " . strlen($jsonData) . "\r\n",
|
|
||||||
'method' => 'POST',
|
|
||||||
'content' => $jsonData,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
$context = stream_context_create($options);
|
|
||||||
$fp = fopen($url, 'r', false, $context);
|
|
||||||
|
|
||||||
// Check for errors
|
|
||||||
if ($fp === FALSE) {
|
|
||||||
echo 'Error occurred';
|
|
||||||
} else {
|
|
||||||
// Read the response
|
|
||||||
$response = stream_get_contents($fp);
|
|
||||||
|
|
||||||
if ($response === FALSE) {
|
|
||||||
echo 'Error reading response';
|
|
||||||
} else {
|
|
||||||
// Print the response
|
|
||||||
if(isset($_GET['send-whatsapp-id'])){
|
|
||||||
$templateName = $_GET['send-whatsapp-id'];
|
|
||||||
} elseif(isset($_GET['send-email-id'])){
|
|
||||||
$templateName = $_GET['send-email-id'];
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
$stmt = $conn->prepare("INSERT INTO communication (leadid, useremail, username, templateid) VALUES (:leadid, :useremail, :username, :templateid)");
|
|
||||||
$stmt->bindParam(':leadid', $_GET['id']);
|
|
||||||
$stmt->bindParam(':useremail', $_SESSION['email']);
|
|
||||||
$stmt->bindParam(':username', $_SESSION['name']);
|
|
||||||
$stmt->bindParam(':templateid', $templateName);
|
|
||||||
$stmt->execute();
|
|
||||||
echo "Message Sent successfully";
|
|
||||||
} catch(PDOException $e) {
|
|
||||||
echo "Error: " . $e->getMessage();
|
|
||||||
}
|
|
||||||
// echo '<script>window.location.href="/edit-lead/?id='.$_GET['id'].'"</script>';
|
|
||||||
// echo $response;
|
|
||||||
}
|
|
||||||
// Close the file pointer
|
|
||||||
fclose($fp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function changeBvValue(){
|
function changeBvValue(){
|
||||||
let verticalsDropDown = document.getElementById('businessVerticals');
|
let verticalsDropDown = document.getElementById('businessVerticals');
|
||||||
@@ -933,11 +989,11 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<style>
|
<style>
|
||||||
#name::selection, #email::selection, #phone::selection {
|
#name::selection {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
#name:focus, #email:focus, #phone:focus {
|
#name:focus, #email:focus, #phone:focus {
|
||||||
outline: none;
|
/* outline: none; */
|
||||||
}
|
}
|
||||||
.flex-container-x2y {
|
.flex-container-x2y {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
Reference in New Issue
Block a user