Viewing File: /home/ubuntu/fansforx_landing_ui/form.php
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Load Composer's autoloader
require 'vendor/autoload.php';
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
$result = file_get_contents(
'https://www.google.com/recaptcha/api/siteverify',
false,
stream_context_create(array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query(array(
'response' => $_POST['g-recaptcha-response'],
'secret' => '6LcrQc4aAAAAALd2Uby7fv8L9qia-T_IQwZu1h_T'
)),
),
))
);
$result = json_decode($result);
if (!$result->success) {
$response = array(
'success' => false,
'message' => "Please confirm that you're not a robot."
);
echo json_encode($response);
exit;
}
try {
//Server settings
// $mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'sarahwatsonfx@gmail.com'; // SMTP username
$mail->Password = 'Fansforx@123'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('Fansforx@gmail.com', 'FansForX');
$mail->addAddress('contact@fansforx.com'); // Name is optional
// $mail->addAddress('ramnethaji.a.l@gmail.com'); // Name is optional
$mail->addReplyTo($_POST['email'], $_POST['full_name']);
// $mail->addCC('cc@example.com');
// $mail->addBCC('bcc@example.com');
// Attachments
// $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = "FansForX - " . $_POST['full_name'];
$message = "Form Content<br/><br/>";
foreach ($_POST as $key => $val) {
if ($key == "g-recaptcha-response") {
continue;
}
$message .= ucfirst($key) . " = " . $val . "<br/>";
}
$mail->Body = $message;
$mail->AltBody = $message;
$mail->send();
$log = "Timestamp: ".date("F j, Y, g:i a").
"Subject: ".$mail->Subject.PHP_EOL.
"Message: ".$mail->Body.PHP_EOL.
"-------------------------".PHP_EOL;
file_put_contents('./logs/form.log', $log, FILE_APPEND);
$response = array(
'success' => true,
'message' => 'Message has been sent'
);
echo json_encode($response);
} catch (Exception $e) {
$response = array(
'success' => false,
'message' => 'Message could not be sent. Please try again later.',
'trace' => $e
);
echo json_encode($response);
}
Back to Directory
File Manager