<?php
/* Sends a simple mail using a helper class (phpmailer.php)
 * May be necessary to turn on less secure apps https://www.google.com/settings/security/lesssecureapps 
 */
require_once("SMTP.php");
require_once("phpmailer.php");

class Mailer{
	public $M;//the mailer
	
	function __construct(){
		$this->M = new phpmailer();
		$this->M->isSMTP();// Set mailer to use SMTP
		
		$this->M->Host = 'smtp.gmail.com';// Specify main and backup SMTP servers
		$this->M->SMTPAuth = true;// Enable SMTP authentication
		$this->M->Username = 'automastersservice@gmail.com';// SMTP username
		$this->M->Password = '@uto$erv';// SMTP password
		$this->M->SMTPSecure = 'ssl';//tls // Enable TLS encryption, `ssl` also accepted
		$this->M->Port = 465;///587; // TCP port to connect to
		
		$this->M->setFrom('info@automastersgh.com', 'AUTOMASTERS GH');
		$this->M->Sender = 'info@automastersgh.com';
	}
	/* Supply these 4 parameters to send a mail */
	function send($address, $name, $subject, $message){
		$sent=false; //mail not sent
		$this->M->Body = $message;
		/*$this->M->AltBody = $altmsg;*/
		$this->M->isHTML(true);
		$this->M->Subject = $subject;
		$this->M->addAddress($address, $name);// Add a recipient
		
		if($this->M->send()) $sent=true; //mail sent 
		$this->M->clearAddresses();
		$this->M->clearAttachments();
		
		return $sent;
	}
}
?>