<?php
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
require_once "Mail.php"; // PEAR Mail package
require_once ('Mail/mime.php'); // PEAR Mail_Mime packge

// extract($_GET);

//Load Composer's autoloader
require 'vendor/autoload.php';

//Create an instance; passing `true` enables exceptions
$sent = false;

try {
    
    $from = "info@confirmid.com.ng"; //enter your email address
    $to = $user->email; //enter the email address of the contact your sending to
    $subject = "ConfirmID Platform Email Verification"; // subject of your email
    
    $headers = array ('From' => $from,'To' => $to, 'Subject' => $subject);

   
    $html    = '<p>Click the link below to reset your pass</p>
                <a href="' . ROOT_URL . '/reset_pass.php?ii=' . base64_encode($user->id) . '&mm=' . base64_encode($user->email) . '">' . ROOT_URL . '/pass_reset.php?ii=' . base64_encode($user->id) . '&mm=' . base64_encode($user->email) . '</a>';
   
    $crlf = "\n";

    
    $mime = new Mail_mime($crlf);
   
    $mime->setHTMLBody($html);
    
    $body = $mime->get();
    $headers = $mime->headers($headers);
    
    $host = "localhost"; // all scripts must use localhost
    $username = "info@confirmid.com.ng"; //  your email address (same as webmail username)
    $password = 'Magerpink12@'; // your password (same as webmail password)


// 'auth' => true,
// 'socket_options' => array('ssl' => array('verify_peer_name' => false, 'allow_self_signed' => true)),


    // $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true,
    // 'username' => $username,'password' => $password));
    $smtp = Mail::factory('smtp',array ('host' => $host,'auth' => true,'socket_options' => array('ssl' => array('verify_peer'=>true,'verify_peer_name' => false, 'allow_self_signed' => false)),'username' => $username,'password' => $password,'port' => '25'));
    $mail = $smtp->send($to, $headers, $body);
    
    if (PEAR::isError($mail)) {
        print_r($mail);
        // $sent = false;
    }
    else {
        // print_r($mail);
        $sent = true;
    }
    
 
} catch (Exception $e) {
    // print_r('failed');
    $sent = false;
    $erro = "Verification mail not sent";
}


