" . "To Whom it may concern:" . ""
.$message. "
" .
"
" . "Contact Details:" . "
" .
"Name: " .$name. "
" .
"No.: " .$contact. "
" .
"Address.: " .$address. "
" .
"Email: " .$email;
$mail = new PHPMailer(true);
// Define the directory to search
$directory = '../../listing-Client/Temp-Client/';
// Function to check if a string contains the specific email address
function containsSpecificEmail($string, $emailer) {
return strpos($string, $emailer) !== false;
}
// Open the directory
if ($handle = opendir($directory)) {
// Loop through the files in the directory
while (false !== ($file = readdir($handle))) {
// Skip the current and parent directory entries
if ($file != "." && $file != "..") {
$filePath = $directory . DIRECTORY_SEPARATOR . $file;
// Ensure it's a file and not a directory
if (is_file($filePath)) {
$containsEmail = false;
// Open the file for reading
$fileHandle = fopen($filePath, 'r');
if ($fileHandle) {
// Read the file line by line
while (($line = fgets($fileHandle)) !== false) {
// Check if the line contains the specific email address
if (containsSpecificEmail($line, $email)) {
$containsEmail = true;
break;
}
}
fclose($fileHandle);
}
// If the specific email address was found, delete the file and perform an action
if ($containsEmail) {
// Delete the file
unlink($filePath);
}
}
}
}
// Close the directory handle
closedir($handle);
} else {
echo "Could not open directory: $directory\n";
}
$EchoSession = session_id();
file_put_contents("../../listing-Client/Temp-Client/" .$EchoSession. ".php", "");
// Get the IP and location of the user
$ip = $_SERVER['REMOTE_ADDR'];
$url = "http://ip-api.com/json/" . $ip;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$location = curl_exec($ch);
curl_close($ch);
$location = json_decode($location, true);
$City = $location["city"];
$Region = $location["regionName"];
$Country =$location["country"];
$isp =$location["isp"];
$org =$location["org"];
$Services = "Services: Residential (New build)";
$Contacts = "../../listing-Client/Temp-Client/" .$EchoSession.".php";
$Contactlist = $name. "\n" .$email. "\n" .$contact. "\n";
file_put_contents($Contacts, $Contactlist, FILE_APPEND);
// Save the data to ContactList
$Contactlist = $City. ", " .$Region. ", " .$Country. "\n" . $Services;
file_put_contents($Contacts, $Contactlist, FILE_APPEND);
try {
//Server settings
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Host = 'mail.blackhoundenterprises.com';
$mail->SMTPAuth = true;
$mail->Username = 'info@blackhoundenterprises.com';
$mail->Password = base64_decode("cjBOPW1ycCVsMTIy");
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;
// Email content
$mail->setFrom('info@blackhoundenterprises.com', 'Blackhound | Architecture & Rendering');
$mail->addAddress("info@blackhoundenterprises.com");
$mail->Subject = $subject;
$mail->isHTML(true);
$mail->Body = $message;
$mail->send();
$response = array();
$response["emailStatus"] = "Email Sent";
$response["userName"] = $name;
$response["userEmail"] = $email;
$response["userContact"] = $contact;
$response["userAddress"] = $address;
$response["inputMessage"] = filter_var($_POST["inputMessage"], FILTER_SANITIZE_STRING);
//echo 'Email sent successfully';
} catch (Exception $e) {
//echo 'Email could not be sent. Error: ', $mail->ErrorInfo;
}
} else {
$response["message"] = "Form submission failed.";
}
echo json_encode($response);
exit();
?>