<?php
class Email{
	
	public function  __construct(){
		require_once('connectdb.php');
		
		$con = new DbConnect;
		$this->con = $con->connect();
		
		require 'admin/production/class/api.php';
		$api = new Api('');
		
		$this->emailHost = $api->getEmailHost();
		$this->emailUsername = $api->getEmailUsername();
		$this->emailPort = $api->getEmailPort();
		$this->emailPassword = $api->getEmailPassword();
		$this->emailSMTP = $api->getSMTPSecure();
	}
	
	public function sendPasswordRecoveryEmail($email, $firstname, $user_id){
		require 'class.phpmailer.php';
		
		$mail = new PHPMailer;
		$mail->IsSMTP();								//Sets Mailer to send message using SMTP
		$mail->Host = $this->emailHost;		//Sets the SMTP hosts of your Email hosting, this for Godaddy
		$mail->Port = $this->emailPort;								//Sets the default SMTP server port
		$mail->SMTPAuth = true;							//Sets SMTP authentication. Utilizes the Username and Password variables
		$mail->Username = $this->emailUsername;					//Sets SMTP username
		$mail->Password = $this->emailPassword;					//Sets SMTP password
		$mail->SMTPSecure = $this->emailSMTP;							//Sets connection prefix. Options are "", "ssl" or "tls"
		$mail->From = 'info@trusteepharmacy.com';			//Sets the From email address for the message
		$mail->FromName = 'Trustee Drugs and Medical Supplies';					//Sets the From name of the message
		$mail->AddAddress($email, $firstname);	//Adds a "To" address
		$mail->WordWrap = 50;							//Sets word wrapping on the body of the message to a given number of characters
		$mail->IsHTML(true);							//Sets message type to HTML
		$mail->Subject = 'Request for password reset on your account'; //Sets the Subject of the message
		//An HTML or plain text message body
		$mail->Body = "
		  Hello 
		  <p>You have requested for a password reset.</p>
		  <p>Click <a href='shop.trusteepharmacy.com/reset-password?user_id=$user_id'>reset password</a> to reset your password</p>
		  <p>Please ignore this email or report to us if you did not initiate this request.</p>
		  <p>Thank you for shooping with us..</p>
		";

		$mail->AltBody = '';

		if($mail->Send()){
		    $output =  'sent';
		}else{
		    $output = 'Mailer Error: ' . $mail->ErrorInfo;
		    exit;
		}
		return $output;
	}

	public function sendPasswordChangeConfirmation($email, $firstname, $user_id){
		require 'class.phpmailer.php';
		
		$mail = new PHPMailer;
		$mail->IsSMTP();								//Sets Mailer to send message using SMTP
		$mail->Host = $this->emailHost;		//Sets the SMTP hosts of your Email hosting, this for Godaddy
		$mail->Port = $this->emailPort;								//Sets the default SMTP server port
		$mail->SMTPAuth = true;							//Sets SMTP authentication. Utilizes the Username and Password variables
		$mail->Username = $this->emailUsername;					//Sets SMTP username
		$mail->Password = $this->emailPassword;					//Sets SMTP password
		$mail->SMTPSecure = $this->emailSMTP;								//Sets connection prefix. Options are "", "ssl" or "tls"
		$mail->From = 'info@trusteepharmacy.com';			//Sets the From email address for the message
		$mail->FromName = 'Trustee Drugs and Medical Supplies';					//Sets the From name of the message
		$mail->AddAddress($email, $firstname);	//Adds a "To" address
		$mail->WordWrap = 50;							//Sets word wrapping on the body of the message to a given number of characters
		$mail->IsHTML(true);							//Sets message type to HTML
		$mail->Subject = 'Password change Successful'; //Sets the Subject of the message
		//An HTML or plain text message body
		$mail->Body = "
		  Hello $firstname,
		  <p>Your password has been changed successfully.</p>
		";

		$mail->AltBody = '';

		if($mail->Send()){
		    $output =  'sent';
		}else{
		    $output = 'Mailer Error: ' . $mail->ErrorInfo;
		    exit;
		}
		return $output;
	}
}

?>