<?php
header("Access-Control-Allow-Origin: *");

require 'vendor/autoload.php';

use PHPMailer\PHPMailer\PHPMailer;

$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Full Name:</strong> </td><td>" . strip_tags($_POST['name']) . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['email']) . "</td></tr>";
$message .= "<tr><td><strong>Phone:</strong> </td><td>" . strip_tags($_POST['phone']) . "</td></tr>";
$message .= "<tr><td><strong>Company:</strong> </td><td>" . strip_tags($_POST['company']) . "</td></tr>";
$message .= "<tr><td><strong>Address:</strong> </td><td>" . strip_tags($_POST['state']) . strip_tags($_POST['suburb']) . "</td></tr>";
$message .= "</table>";

$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'compustorau@gmail.com';
$mail->Password = 'C0mpust0r!!2014!!';

$mail->setFrom('compustorau@gmail.com', 'Compu Stor');
$mail->addReplyTo('compustorau@gmail.com', 'Compu Stor');
$mail->addAddress('business.support@compu-stor.com.au', 'Compu Stor');
$mail->addBcc('team@propagate.com.au');
$mail->Subject = 'Form Submission: ' . isset($_POST['landing-page']) ? $_POST['landing-page'] : '';
$mail->isHTML(true);
$mail->Body = $message;
$mail->AltBody = 'New Form Submission';
if (!$mail->send()) {
    echo 'Mailer Error: ' . $mail->ErrorInfo;
    die();
} else {
    echo 'Message sent!';
}
?>
