Mini Shell
<?php
require "_extras/Exception.php";
require "_extras/PHPMailer.php";
require "_extras/SMTP.php";
require "_extras/Attachment.php";
require_once "_framework/Configuration.php";
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
class Mail {
private $smtpserver;
private $smtpproto;
private $smtpport;
private $smtpuser;
private $smtppassword;
private $msgfrom;
private $replyto;
private $telreply;
private $mail;
private $emailText;
private $subject;
private $logoImg;
private $attachments;
public function __construct($template,$subject) {
$this->smtpserver = Configuration::get("smtpserver");
$this->smtpproto = Configuration::get("smtpproto");
$this->smtpport = Configuration::get("smtpport");
$this->smtpuser = Configuration::get("smtpuser");
$this->smtppassword = Configuration::get("smtppassword");
$this->msgfrom = Configuration::get("msgfrom");
$this->replyto = Configuration::get("replyto");
$this->telreply = Configuration::get("telreply");
$this->logoImg = Configuration::get("logo_site");
$this->mail = new PHPMailer();
if(file_exists($template)) {
$this->emailText = file_get_contents($template);
} else {
$this->emailText = "<h1>Mail template not found</h1>";
}
$this->subject = $subject;
$this->attachments = array();
}
public function sendEmail($to) {
set_time_limit(1500);
$this->mail->IsSMTP();
$this->mail->SMTPDebug = 2;
$this->mail->SMTPAuth = true;
$this->mail->SMTPSecure = $this->smtpproto;
$this->mail->Host = $this->smtpserver;
$this->mail->Port = $this->smtpport;
$this->mail->Username = $this->smtpuser;
$this->mail->Password = $this->smtppassword;
$this->mail->CharSet = 'UTF-8';
$this->mail->SetFrom($this->msgfrom);
$this->mail->Subject = $this->subject;
$this->mail->ContentType = 'text/plain';
$this->mail->IsHTML(true);
$this->mail->Body = $this->emailText;
$this->mail->AddAddress($to);
$this->mail->AddEmbeddedImage($this->logoImg, 'logo');
if(!empty($this->attachments)) {
foreach($this->attachments as $obj) {
$this->mail->AddStringAttachment($obj->content,$obj->filename);
}
}
die(var_dump($this));
if(!$this->mail->Send())
{
return "Erreur : " . $this->mail->ErrorInfo;
} else {
return true;
}
}
public function replaceVars($vars) {
foreach($vars as $key => $value) {
$this->emailText = str_replace($key,$value,$this->emailText);
}
}
public function addAttachment($attachment) {
$obj = new Attachment();
$obj = $attachment;
array_push($this->attachments,$obj);
}
}