94 lines
2.1 KiB
PHP
94 lines
2.1 KiB
PHP
<?php
|
|
/*
|
|
Author: Riccardo Di Dato
|
|
Creation Date: 25/gen/2016
|
|
*/
|
|
|
|
|
|
class MailModel extends Model implements FDN_MailInterface{
|
|
const STATUS_PENDING = 0;
|
|
const STATUS_SENT = 1;
|
|
const STATUS_PAUSED = 2;
|
|
|
|
const PRIORITY_HIGH = 100;
|
|
const PRIORITY_NORMAL = 50;
|
|
const PRIORITY_LOW = 10;
|
|
|
|
|
|
public function __construct($saveableObject = null){
|
|
parent::__construct($saveableObject);
|
|
|
|
$requiredProps = array("from","subject","body","recipient");
|
|
|
|
if (!$this->hasProperty("status")){
|
|
$this->status = self::STATUS_PENDING;
|
|
}
|
|
|
|
if (!$this->hasProperty("priority")){
|
|
$this->priority = self::PRIORITY_NORMAL;
|
|
}
|
|
|
|
foreach ($requiredProps as $prop){
|
|
if (!$this->hasProperty($prop)){
|
|
throw new CoreException("Missing parameter '$prop' while calling MailModel::__construct()");
|
|
}
|
|
}
|
|
}
|
|
|
|
public function __set($attr,$value){
|
|
if (strcmp("status", $attr)==0 || strcmp("priority", $attr)==0){
|
|
$value = intval($value);
|
|
}
|
|
return parent::__set($attr, $value);
|
|
}
|
|
|
|
|
|
public function getMailObject() {
|
|
$email = new PHPMailer();
|
|
$email->CharSet = "UTF-8";
|
|
$email->isMail();
|
|
|
|
$email->From = $this->from;
|
|
if ($this->hasProperty("fromName")){
|
|
$email->FromName = $this->fromName;
|
|
}
|
|
|
|
$email->Subject = $this->subject;
|
|
|
|
$email->IsHTML(true);
|
|
|
|
|
|
$email->Body = $this->body;
|
|
if ($this->hasProperty("altBody")){
|
|
$email->AltBody = $this->altBody;
|
|
}
|
|
else {
|
|
$email->AltBody = strip_tags($this->body);
|
|
}
|
|
|
|
|
|
$email->AddAddress($this->recipient);
|
|
|
|
if ($this->hasProperty("attachment")){
|
|
$email->AddAttachment( $this->attachment , basename($this->attachment) );
|
|
}
|
|
|
|
$cfg = GlobalVariables::get("config");
|
|
|
|
$email->IsSMTP();
|
|
$email->Host = $cfg->mailer->address;
|
|
$email->Port = $cfg->mailer->port;
|
|
$email->Username = $cfg->mailer->username;
|
|
$email->Password = $cfg->mailer->password;
|
|
$email->SMTPAuth = $cfg->mailer->smtpAuth;
|
|
|
|
return $email;
|
|
}
|
|
|
|
public static function getCollectionName(){
|
|
return "mail";
|
|
}
|
|
|
|
}
|
|
|
|
?>
|