<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require_once "vendor/autoload.php";


$server = $_SERVER['HTTP_REFERER'];
if($server == "https://f45.af/info/"){
    $mail = new PHPMailer(true);
    $mail->From = "lead@f45.af";
    $mail->FromName = "F45";
    
    $mail = new PHPMailer(true);

    //Enable SMTP debugging.
    $mail->SMTPDebug = 3;                               
    //Set PHPMailer to use SMTP.
    $mail->isSMTP();            
    //Set SMTP host name                          
    $mail->Host = "mail.f45.af";
    //Set this to true if SMTP host requires authentication to send email
    $mail->SMTPAuth = true;                          
    //Provide username and password     
    $mail->Username = "lead@f45.af";                 
    $mail->Password = "[M,x=@jQ%=_E";                           
    //If SMTP requires TLS encryption then set it
    $mail->SMTPSecure = "tls";                           
    //Set TCP port to connect to
    $mail->Port = 465;                                   
    
    $lang=$_POST["lang"];
    $fname=$_POST["fname"];
    $lname=$_POST["lname"];
    $email=$_POST["email"];
    $phone=$_POST["phone"];
    $studio=$_POST["location"];
    $subject = "My subject";
    
    $mail->addAddress("mateen.rahmat@ahg.af");
    $mail->addReplyTo("mateen.rahmat@ahg.af", "Reply");
    
    $mail->isHTML(true);
    $mail->Subject = "User Registered";
    $mail->Body = "<i>Mail body in HTML</i>";
    if($fname AND $laname AND $email AND $phone AND $studio){
    $mailBody="First Name: $fname \n Last Name: $lname \n Email: $email; \n
    Phone Number: $phone";
    $mail->AltBody = $mailBody;
    
    try {
    $mail->send();
    echo "Message has been sent successfully";
    } catch (Exception $e) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    }
    }
    }
    else{
        echo "not allowed";
    };
?>