Viewing File: /home/ubuntu/fansforx_landing_ui/src/index.php

<?php
use PHPMailer\PHPMailer\PHPMailer;

use PHPMailer\PHPMailer\Exception;

require_once '../vendor/autoload.php';

require_once 'FormHandler.php';

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// Check the submission is not spam 

$ip = $_SERVER['REMOTE_ADDR'];

$fp = fopen('spam_log.txt', 'a');

fwrite($fp, 'LOG::INFO: DATE: '.date('Y-m-d H:i:s').' IP: '.$ip."\n");

fclose($fp);

$mail = new PHPMailer;

if (empty($_POST['name']) || empty($_POST['email']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) || !isset($_POST["csrf_token"]) || $_POST["csrf_token"] !== "") {
    $data['success'] = false;
    $data['message'] = "Please fill all the fields";
    header("Content-Type: application/json; charset=utf-8", true);
    header('Location: ../contact-us.html');
    return json_encode($data);
}

if (strstr($_POST['name'], 'http') || strstr($_POST['name'], 'www') || strstr($_POST['message'], 'http') || strstr($_POST['message'], 'www')){
    // $data['success'] = false;
    // $data['message'] = "Please fill all the fields";
    // header("Content-Type: application/json; charset=utf-8", true);
    // header('Location: ../contact-us.html');
    // return json_encode($data);
} 

$name          = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$subject       = "Thanks for contacting us";
$message       = $_POST['message'] ? strip_tags(htmlspecialchars($_POST['message'])) : '';
$phone         = strip_tags(htmlspecialchars($_POST['phone']));

//Disable SMTP debugging. 
$mail->SMTPDebug = 0;

$mail->SingleTo = true;

//Set PHPMailer to use SMTP.
$mail->isSMTP();
//Set SMTP host name                          
$mail->Host       = "smtp.gmail.com";
$mail->SMTPAuth   = true;
//Provide username and password  
$mail->Username   = "sarahwatsonfx@gmail.com";
$mail->Password   = "bynbewvgjbwahtej";
//If SMTP requires TLS encryption then set it
$mail->SMTPSecure = "ssl";
//Set TCP port to connect to 
$mail->Port       = 465;
//Recipients
$mail->setFrom('contact@fansforx.com', 'Suraj');
$mail->addAddress($_POST['email'], $_POST['name']); //Add a recipient
$mail->addReplyTo('contact@fansforx.com', "Suraj");

$mail->isHTML(true);

$mail->Subject = "FansForX - " . $subject;

$mail->Body = "Hello ".$name.',';

$mail->Body .= "<p style='font-size: 14px;'>Thanks for contacting us!</p>";

$mail->Body .= "<p style='font-size: 14px;'>One of our executive members from <b>FansForX</b> will reach out to you shortly.</p>";

$mail->Body .= "<p style='font-size: 14px;'>Meanwhile here are a couple of reviews as to what our clients have to say about us:</p>";

$mail->Body .= "<p style='font-size: 14px;'><span style='color: #6730e3'><b>Testimonial 1</b></span> - "."<a href='https://youtu.be/4deri_4ZkMo' target='_blank'>Marc Schneider</a></p>";

$mail->Body .= "<p style='font-size: 14px;'><span style='color: #6730e3'><b>Testimonial 2</b><span> - "."<a href='https://youtu.be/K80cfneXnnU' target='_blank'>Rochi</a></p>";

$mail->Body .= "<p style='font-size: 14px;'>Also, here is our 24/7 Chat line where you can have a 1 to 1 conversations with one of our executives regarding your queries or requirements - "."<a href='https://api.whatsapp.com/send?phone=+917760163989&text=I%27m%20interested%20in%20fansforx' target='_blank'><b>CHAT NOW</b></a></p>";

$mail->Body .= "<p style='font-size: 14px;'>Thanks & Regards,";
$mail->Body .= "<br>Suraj</p>";

$mail->AltBody = "Thanks for Contacting Us!! Will contact you soon.";

if ($mail->send()) {
    
    $mail->ClearAddresses();
    
    $data['success'] = true;
    
    $data['message'] = "Mail sent";
    
    header("Content-Type: application/json; charset=utf-8", true);
    
    // echo json_encode($data);
    
} else {
    
    $data['success'] = false;
    
    $data['message'] = "Mail Failed";
    
    header("Content-Type: application/json; charset=utf-8", true);
    
    // echo json_encode($data);
}


// OUR SUPPORT

$owner_mail = new PHPMailer;

//Disable SMTP debugging. 
$owner_mail->SMTPDebug = 0;

$owner_mail->SingleTo = true;

//Set PHPMailer to use SMTP.
$owner_mail->isSMTP();
//Set SMTP host name                          
$owner_mail->Host = "smtp.gmail.com";

//Set this to true if SMTP host requires authentication to send email
//Provide username and password    
$owner_mail->SMTPAuth = true;

$owner_mail->Username   = "sarahwatsonfx@gmail.com";
$owner_mail->Password   = "oleqqzemcavooxes";
//If SMTP requires TLS encryption then set it
$owner_mail->SMTPSecure = "ssl";
//Set TCP port to connect to 
$owner_mail->Port       = 465;

$owner_mail->setFrom($email_address, $name);

$owner_mail->addReplyTo($email_address, $name);

// $mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$owner_mail->addAddress('contact@fansforx.com', "Suraj");

$owner_mail->AddBCC('mail@aravinth.net', 'Aravinth Ramesh');
$owner_mail->isHTML(true);

$owner_mail->Subject = "FansForX - Contact Form Submission " . $name;

$owner_mail->Body = "Hello " . ',<br><br>';

$owner_mail->Body .= "Name: " . $name . '<br><br>';

$owner_mail->Body .= "Email: " . $email_address . '<br><br>';

$owner_mail->Body .= "Mobile: " . $phone . '<br><br>';

if ($message) {
    
    $owner_mail->Body .= "Message: " . '<br><br>';
    
    $owner_mail->Body .= $message . '.<br><br>';
    
}

$owner_mail->AltBody = "Name: " . $name . ", Email:" . $email_address . ", Phone:" . $phone . ", message:" . $message;


if ($owner_mail->send()) {
    
    $owner_mail->ClearAddresses();
    
    $data['success'] = true;
    
    $data['message'] = "Mail sent";
    
    header("Content-Type: application/json; charset=utf-8", true);
    
    // echo json_encode($data);
} else {
    
    $data['success'] = false;
    
    $data['message'] = "Mail Failed";
    
    header("Content-Type: application/json; charset=utf-8", true);
    // echo json_encode($data);
}

$data['success'] = true;
$data['message'] = "Mail sent";

header('Content-type: application/json');
header('Location: ../thanks.html');
Back to Directory File Manager