<?php include_once($_SERVER['DOCUMENT_ROOT'].'/_ps2020/_global/dir_root.php'); ?>

<?php


use PHPMailer\PHPMailer\PHPMailer;
    
    if(isset($_REQUEST['name']) && isset($_REQUEST['email'])){
        $name = $_REQUEST['name'];
        $email = $_REQUEST['email'];
        $subject = $_REQUEST['subject'];
        $body = $_REQUEST['body'];

        $name = "(no-reply) Team GEESE";
        
        
        $body = "
            <html> 
                <body style='color: #000; font-size: 16px; text-decoration: none; font-family:  Helvetica, Arial, sans-serif; background-color: #efefef;'>
                    
                    <div id='wrapper' style='max-width: 800px; margin: auto auto; padding: 20px;'>
                        
                        <div id='logo'>
                            <center><h1><a href='https://ps2020.cdms.westernsydney.edu.au/".dir_root."images/logov1.png' target='_blank'><img style='max-height: 75px;' src='https://ps2020.cdms.westernsydney.edu.au/".dir_root."images/logov1.png'></a></h1></center>
                        </div>
                            
                        <div id='content' style='font-size: 16px; padding: 50px; background-color: white; box-shadow: 0 0 15px #548b54;
                            moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px; -khtml-border-radius: 10px;
                            '>
            
                            <h1 style='font-size: 22px;'><center>" . $email . "</center></h1>
                            
                            <p>Hi " . $username . ",</p>
            
                            <p>We are team behined project GEESE. We would like to extend our gratitude for your joining to GEESE Surveys.</p>

                            <p>Although your account has already been setup. But we need to verify your account before you can use it.</p>

                            <p>This is just to validate your input credentials, and for security reasons and we research purposes.</p>

                            <p>Once you sign-up/sign-in for the first time you will directed to a page to activate your account by putting in a specific verify code generated from our website.</p>

                            <p>Your verification code is: <b>{VERIFY_CODE}</b></p>
            
                            <!-- <p style='display: flex; justify-content: center; margin-top: 10px;'>
                                <center>
                                    <a href='{CUSTOM_URL}' target='_blank' style='border: 1px solid #0561B3; background-color: #548b54; color: #fff; text-decoration: none; font-size: 18px; padding: 10px 20px;'>Activate Account</a>
                                </center>
                            </p> -->
                            
                        </div>

                    </div>
                </body>
            </html>";



        require_once "PHPMailer/PHPMailer.php";
        require_once "PHPMailer/SMTP.php";
        require_once "PHPMailer/Exception.php";

        $mail = new PHPMailer();
        //smtp settings
        $mail->isSMTP();
        $mail->Host = "smtp.gmail.com";
        $mail->SMTPAuth = true;
        $mail->Username = "teamgesse2020@gmail.com";
        //Enter your password and replace you gmail above with mine
        $mail->Password = "teamgeese1234";
        $mail->Port = 465;
        $mail->SMTPSecure = "ssl";

        //Email Settings
        $mail->isHTML(true);
        $mail->setFrom($email,$name);
        $mail->addAddress($email);
        $mail->Subject = 'GEESE Verification Code';  // $subject
        $mail->Body = $body;

        if($mail->send()){
            $status = "Success";
            $response = "Email is Sent";
            exit(json_encode(array("status" => $status, "response" => $response)));
        }else{
            $status = "Failed!";
            $response = "Email couldn't be sent: " . $mail->ErrorInfo;
            exit(json_encode(array("status" => $status, "response" => $response)));
        }

    }

    ?>

    // 

    // function sendEmail($verifyCode){

    //     $username = $_SESSION['user'];
    //     $email = $_SESSION['email'];

        // $body = "
        <!-- <html> 
    //     <body style='color: #000; font-size: 16px; text-decoration: none; font-family:  Helvetica, Arial, sans-serif; background-color: #efefef;'>
            
    //         <div id='wrapper' style='max-width: 600px; margin: auto auto; padding: 20px;'>
                
    //             <div id='logo'>
    //                 <center><h1 style='margin: 0px;'><a href='{SITE_ADDR}' target='_blank'><img style='max-height: 75px;' src='{EMAIL_LOGO}'></a></h1></center>
    //             </div>
                    
    //             <div id='content' style='font-size: 16px; padding: 25px; background-color: #90909013;
    //                 moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px; -khtml-border-radius: 10px;
    //                 border-color: limegreen; border-width: 4px 1px; border-style: solid;'>
    
    //             <h1 style='font-size: 22px;'><center>Verify GEESE Account!</center></h1>
                    
    //             <p>Hi " . $username . ",</p>
    
    //             <p>We are team behined project GEESE. We would to extend our gratitude for joining GEESE Surveys.</p>

	// 			<p>Although your account has already been setup. But we need to verify your account before you can use it.</p>

	// 			<p>This is just to validate your input credentials. This is just for security reasons and we research purposes.</p>

	// 			<p>Once you sign-up/sign-in for the first time you will directed to a verify email form. The verify code for your account is below.</p>
				
	// 			<p>Your verification code is: <b>" . $verifyCode ."</b></p>
    
    //                 <p style='display: flex; justify-content: center; margin-top: 10px;'><center>
    //                     <a href='{CUSTOM_URL}' target='_blank' style='border: 1px solid #0561B3; background-color: #548b54; color: #fff; text-decoration: none; font-size: 18px; padding: 10px 20px;'>Activate Account</a></div>
    //                 </center></p>
                    
    //             </div>
    
    //             <div id='footer' style='margin-bottom: 20px; padding: 0px 8px; text-align: center;'>
    //                 For furthur enquires or queries come visit us at :<a href='https://www.heytuts.com/web-dev' target='_blank' style='text-decoration: none; color: #238CEA;'> GEESE-Platform.</a> 
    //             </div>
    //         </div>
    //     </body>
    // </html> -->
    ";

    // require_once "PHPMailer/PHPMailer.php";
    // require_once "PHPMailer/SMTP.php";
    // require_once "PHPMailer/Exception.php";

    // $name = "TEAM GEESE";
    // $subject = "VERIFY GEESE ACCOUNT";

    // $mail = new PHPMailer();
    // //smtp settings
    // $mail->isSMTP();
    // $mail->Host = "smtp.gmail.com";
    // $mail->SMTPAuth = true;
    // $mail->Username = "teamgesse2020@gmail.com";
    // //Enter your password and replace you gmail above with mine
    // $mail->Password = "tanujjain140498";
    // $mail->Port = 465;
    // $mail->SMTPSecure = "ssl";

    // $mail->isHTML(true);
    // //This set the name which appears to the user who recieves the email
    // $mail->setFrom($email,$name);
    // //This cc the email to teamgeese2020@gmail.com
    // $mail->addAddress($email);
    // $mail->Subject = $subject;
    // $mail->Body = $body;

    // if($mail->send()){
    //     $status = "Success";
    //     $response = "Email is Sent";
    //     exit(json_encode(array("status" => $status, "response" => $response)));
    // }else{
    //     $status = "Failed!";
    //     $response = "Email couldn't be sent: " . $mail->ErrorInfo;
    //     exit(json_encode(array("status" => $status, "response" => $response)));
    // }


    // }

