File: /home/qhl5pt3kkb1d/public_html/tstp-old/contact_mail.php
<?php
$date = date('d-m-Y h:i:s a');
$success = '';
$message = '';
$code = '';
// define variables and set to empty values
$nameErr = $emailErr = $phonenoErr = $inquiryErr = "";
$name = $email = $phoneno = $inquiry = "";
if (empty($_POST["your-name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["your-name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z-' ]*$/", $name)) {
$nameErr = "Only letters and white space allowed";
}
}
if (empty($_POST["your-email"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["your-email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
if (empty($_POST["your-phone"])) {
$phonenoErr = "phone number is required";
} else {
$phone = test_input($_POST["your-phone"]);
}
if (empty($_POST["inquiry"])) {
$inquiryErr = "Inquiry by is required";
} else {
$inquiry = test_input($_POST["inquiry"]);
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if ($emailErr == "" && $nameErr == "" && $phonenoErr == "" && $inquiryErr == "") {
// $name = $_POST['your-name'];
// $email = $_POST['your-email'];
// $phone = $_POST['your-phone'];
// $inquiry = $_POST['inquiry'];
$reference = $_POST['about'];
$message = $_POST['your-message'];
$comm1 = "";
$comm2 = "";
$comm3 = "";
$comm4 = "";
$comm5 = "";
if (!empty($_POST['cource1'])) {
$comm1 = ",";
}
if (!empty($_POST['cource1']) || !empty($_POST['cource2'])) {
$comm2 = ",";
}
if (!empty($_POST['cource1']) || !empty($_POST['cource2']) || !empty($_POST['cource3'])) {
$comm3 = ",";
}
if (!empty($_POST['cource1']) || !empty($_POST['cource2']) || !empty($_POST['cource3']) || !empty($_POST['cource4'])) {
$comm4 = ",";
}
if (!empty($_POST['cource1']) || !empty($_POST['cource2']) || !empty($_POST['cource3']) || !empty($_POST['cource4']) || !empty($_POST['cource5'])) {
$comm5 = ",";
}
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.brevo.com/v3/smtp/email",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
"sender" => [
"name" => "Info TSTP ",
"email" => "info@tstp.in"
],
"to" => [
[
"name" => "Shailendra Garg",
"email" => "shailendra@tstp.in"
]
],
"cc" => [
[
"name" => "BrownFox",
"email" => "brownfox.consultant@gmail.com"
]
],
'htmlContent' => '<!DOCTYPE html>
<html lang="en">
<head>
<title>The Smart Test Prep - Experience Better Learning</title>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td align="center">
<table class="col-600" width="600" border="0" align="center" cellpadding="0" cellspacing="0" style="margin-left:20px; margin-right:20px;margin-top:20px;">
<tbody>
<tr>
<td align="center" valign="top" style="background-size:cover; background-position:top;height:400">
<table class="col-600" width="600" height="400" border="0" align="center" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td align="center" style="line-height: 0px;">
<img style="display:block; line-height:0px; font-size:0px; border:0px;" src="https://thesmarttestprep.com/images/logo.png" width="400" height="103" alt="logo">
</td>
</tr>
<tr>
<td style="font-family: Raleway, sans-serif; font-size:20px; color:#000000; line-height:2px;">
Hi,
</td>
</tr>
<tr>
<td style="font-family: Raleway, sans-serif; font-size:20px; color:#000000;">
New lead <b>Contact us</b> generated from the website.
</td>
</tr>
<tr>
<td height="20"></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td align="center">
<table class="col-600" width="600" border="0" align="center" cellpadding="0" cellspacing="0" style="margin-left:20px; margin-right:20px; margin-bottom: 20px;">
<tbody>
<tr>
<td style="font-family: Raleway, sans-serif; font-size:18px; color:#000000;"><b>Name : </b>' . $name . '</td>
</tr>
<tr>
<td height="10"></td>
</tr>
<tr>
<td style="font-family: Raleway, sans-serif; font-size:18px; color:#000000;"><b>Email : </b>' . $email . '</td>
</tr>
<tr>
<td height="10"></td>
</tr>
<tr>
<td style="font-family: Raleway, sans-serif; font-size:18px; color:#000000;"><b>Phone : </b>' . $phone . '</td>
</tr>
<tr>
<td height="10"></td>
</tr>
<tr>
<td style="font-family: Raleway, sans-serif; font-size:18px; color:#000000;"><b>Course : </b>' . (!empty($_POST['cource1']) ? $_POST['cource1'] : '') . ' ' . (!empty($_POST['cource2']) ? $comm1 . $_POST['cource2'] : '') . ' ' . (!empty($_POST['cource3']) ? $comm2 . $_POST['cource3'] : '') . ' ' . (!empty($_POST['cource4']) ? $comm3 . $_POST['cource4'] : '') . ' ' . (!empty($_POST['cource5']) ? $comm4 . $_POST['cource5'] : '') . ' ' . (!empty($_POST['cource6']) ? $comm5 . $_POST['cource6'] : '') . '</td>
</tr>
<tr>
<td height="10"></td>
</tr>
<tr>
<td style="font-family: Raleway, sans-serif; font-size:18px; color:#000000;"><b>Inquiry By: </b>' . $inquiry . '</td>
</tr>
<tr>
<td height="10"></td>
</tr>
<tr>
<td style="font-family: Raleway, sans-serif; font-size:18px; color:#000000;"><b>How you came to know about us? : </b>' . $reference . '</td>
</tr>
<tr>
<td height="10"></td>
</tr>
<tr>
<td style="font-family: Raleway, sans-serif; font-size:18px; color:#000000;"><b>Message : </b>' . $message . '</td>
</tr>
<tr>
<td height="10"></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td height="5"></td>
</tr>
</tbody>
</table>
</body>
</html>',
'subject' => 'Contact us Inquire From The Smart Test Prep',
]),
CURLOPT_HTTPHEADER => [
"accept: application/json",
"api-key: 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",
"content-type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if($err) {
$success = false;
$code = "1";
$message = "<p>" . $err . "</p>";
} else {
$success = true;
$code = "2";
$message = "Email Sent Successfully.";
}
} else {
$success = false;
$code = "3";
$message = "<p>" . $nameErr . "</p><p>" . $emailErr . "</p><p>" . $phonenoErr . "</p><p>" . $inquiryErr . "</p>";
}
$data['success'] = $success;
$data['code'] = $code;
$data['message'] = $message;
echo json_encode($data);
?>