<?
require_once("include/phpmailer/class.phpmailer.php");

class mailEnvia extends phpmailer{

	var $myhost;
	var $mylink;

	function mailEnvia(){
		require_once("config/config.mail.inc.php");
		
		
		////$mail = new PHPMailer();
		//$mail->PluginDir = "/path/to/phpmailer/dir";
		$this->IsSMTP();                                   // send via SMTP
		///////////var $Mailer   = "smtp";
		$this->Host = $mailHost; // SMTP servers
		
		if ($mailAuth) {
			$this->SMTPAuth = true; 
			$this->Username = $mailUsername;  // SMTP username
			$this->Password = $mailPassword; 
		}
		//$this->Priority=3;
		//$this->Encoding="quoted-printable";
		//$this->IsHTML(true);                               // send as HTML
		//$mail->AltBody  =  $textbody;
		$this->From     = $mailFrom;
		$this->FromName = $mailFromName;
		//print_rr($_REQUEST['mailCat']);
		$this->myhost=$myhost;
		$this->mylink=$mylink;
		
	}

	function sendTo(){
		////	
		$db=new dbElemento();
				
		$this->Subject  = $this->assunto;

		$sql ="SELECT * from utilizador where estado=1";
		$dados=$db->get($sql);
		$rows=sizeof($dados);
		//$nCiclos=ceil($rows/$numeroMails);

		if ($rows) print "Enviando mails<br>";
		
		$erro_mail="";
		$m=0;
	// ciclo para escolhidos
		for ($m=0;$m<$rows;$m++){
		//for ($i=0;$i<$nCiclos;$i++){
			//for ($j=0;$j< $numeroMails; $j++){
				
				if ($dados[$m]['email']=="") continue;
				$email= $dados[$m]['email'];
				$nome= $dados[$m]['nome'];

				$this->Body    = $this->texto;

				$this->AddAddress($email, $nome);
				//$this->AddBcc("americo.rio@itcode.pt", "americo");
				
				
				if ($mailDebug) 
					print "$m - $email - $nome - $erro_mail<br>";
				else	
					print "$m, " ;
				
				//$m++;
				if(!$this->Send()) echo $erro_mail="Ocorreu um erro com o mail <br><br>";
				//$mail->ClearAllRecipients();
				$this->ClearAddresses();
				////$mail->ClearAttachments();
			//}

		}
		
		if (empty($erro_mail)) {
			print "Concluído"; 
		}
	}
	

}
?>
