<?php

class myPHPMail {
  private $mailer;

  public function __construct() {
    require_once(sfConfig::get('sf_symfony_lib_dir').'/vendor/phpmailer/class.phpmailer.php');
    require_once(sfConfig::get('sf_symfony_lib_dir').'/vendor/phpmailer/class.smtp.php');

    $this->mailer = new PHPMailer();
    $this->mailer->Host = '127.0.0.1';
    $this->mailer->CharSet = 'utf-8';
    $this->mailer->ContentType = 'text/html';
    $this->setFrom('hotro@violet.vn', 'Thu vien Violet');
  }

  public function setFrom($address, $name = null) {
    $this->mailer->From = $address;
    $this->mailer->FromName = $name;
  }

  private $receiverInfo = '';
  public function addAddress($address, $name = null) {
    $this->mailer->AddAddress($address, $name);
    $this->receiverInfo = $name.' <'.$address.'>';  //for logging at send()
  }

  public function addReplyTo($address, $name = null) {
    $this->mailer->AddReplyTo($address, $name);
  }

  public function setSubject($subject) {
    $this->mailer->Subject = $subject;
  }

  public function setBody($body) {
    $this->mailer->Body = $body;
  }

  public function send() {
    myUtility::log($this->receiverInfo.' "'.$this->mailer->Subject.'"', 'mail.log');
    return $this->mailer->Send();
  }
}
