<?php

include 'db.php';


include 'mailer/vendor/autoload.php';

use PHPMailer\PHPMailer\PHPMailer;

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


 function sendMail($email, $subject, $message){

    $mail = new PHPMailer();
    //SMTP Settings (use default cpanel email account)
    $mail->isSMTP();
    $mail->Host = "gcxpressco.com"; //
    $mail->SMTPAuth = true;
    $mail->Username = "support@gcxpressco.com"; // Default cpanel email account
    $mail->Password = 'gcxpressco@123'; // Default cpanel email password
    $mail->Port = 465; // 587
    $mail->SMTPSecure = "ssl"; // tls

    //Email Settings
    $mail->isHTML(true);
    $mail->setFrom('support@gcxpressco.com','Global Cargo Xpress Company'); // Email address/ Bank bane shown to reciever
    $mail->addAddress($email);
    $mail->AddReplyTo("support@gcxpressco.com", "Global Cargo Xpress Company"); // Email address/ Bank bane shown to reciever
    $mail->Subject = $subject;
    $mail->MsgHTML($message);
    $send = $mail->Send();
    return $send;
}

$sql = mysqli_query($link, "SELECT * FROM settings WHERE id = 1 ");
if (mysqli_num_rows($sql) > 0) {
	$data = mysqli_fetch_assoc($sql);
	$track_prefix = $data['track_prefix'];
	$track_num = $data['track_num'];
	$invoice_terms = $data['invoice_terms'];
	$allow_print = $data['allow_print'];
	$show_map = $data['show_map'];

	$email_name = $data['email_name'];
	$email_address = $data['email_address'];
	$mail_track_update = $data['mail_track_update'];
	$mail_track_save = $data['mail_track_save'];

	$sitename = $data['sitename'];
	$site_title = $data['site_title'];
	$site_url = $data['site_url'];
	$site_logo = $data['site_logo'];

	$phone = $data['phone'];
	$address = $data['address'];
}

// function sendMail($email, $subject, $body)
// {
// 	global $email_address, $email_name;
// 	$message = "$body";
// 	$headers = "MIME-Version: 1.0" . "\r\n";
// 	$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// 	// $headers .= 'From: ' . $email_name . '<' . $email_address . '>' . "\r\n";
// 	$headers .= 'From:' . $email_name . ' support@traders.freetutorz.tech' . "\r\n";
// 	return mail($email, $subject, $message, $headers);
// }


// function sendMail($email, $subject, $message)
// {
// 	global $email_address, $email_name;
// 	$to = "$email";

// 	// Always set content-type when sending HTML email
// 	$headers = "MIME-Version: 1.0" . "\r\n";
// 	$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// 	// More headers
// 	$headers .= "from: $email_name $email_address" . "\r\n";
// 	$headers .= "Reply-To: $email_address \r\n";
// 	$headers .= "Return-Path: $email_address\r\n";
// 	// $headers .= "CC: $website_email\r\n";
// 	$headers .= "BCC: $email_address\r\n";

// 	return mail($to, $subject, $message, $headers, "-f $email_address");
// }
