<?php

class myMail {
  
  public $setFrom;
  public $From;
  public $FromName;
  public $To;
  public $ToName;
  public $Subject;
  public $Body;
  public $ReplyTo;
  
  public function __construct() {
    $this->setFrom('hotro@violet.vn', 'Thu vien Violet');
  }

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

  public function addAddress($address, $name = null) {
    $this->To = $address;
    $this->ToName = $name;
  }

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

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

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

  public function send() {
    $url = 'http://54.254.211.41';
    $postData = array();
    $postData['from'] = $this->From;
    $postData['fromname'] = $this->FromName;
    $postData['replyto'] = $this->ReplyTo;
    $postData['to'] = $this->To;
    $postData['toname'] = $this->ToName;
    $postData['subject'] = $this->Subject;
    $postData['content'] = $this->Body;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
    $result = curl_exec($ch);
    curl_close($ch);
    myUtility::log($this->ToName.' <'.$this->To.'> "'.$this->Subject.'"', 'mail.log');
    return $result=='true';
  }
}
