2019-09-15 18:08:44 +01:00
|
|
|
<?php
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
|
|
use PHPMailer\PHPMailer\Exception;
|
|
|
|
|
|
|
|
|
|
|
|
class MailWrapper
|
|
|
|
{
|
|
|
|
|
2019-09-15 20:27:26 +02:00
|
|
|
private $fqm, $host, $protocol, $replyto, $from, $fromName;
|
2019-09-15 18:08:44 +01:00
|
|
|
|
|
|
|
private $recipient;
|
|
|
|
|
|
|
|
private $mailer;
|
|
|
|
|
|
|
|
private $authpassword;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->mailer = new PHPMailer(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function prepare()
|
|
|
|
{
|
|
|
|
$this->mailer->isSMTP();
|
|
|
|
$this->mailer->Host = $this->host;
|
|
|
|
$this->mailer->SMTPAuth = true;
|
|
|
|
$this->mailer->Username = $this->fqm;
|
|
|
|
$this->mailer->Password = $this->authpassword;
|
|
|
|
$this->mailer->SMTPSecure = $this->protocol;
|
|
|
|
$this->mailer->Port = ($this->protocol == "tls") ? '587' : '465';
|
|
|
|
|
2019-09-15 20:27:26 +02:00
|
|
|
$this->mailer->setFrom($this->from, $this->fromName);
|
2019-09-15 18:08:44 +01:00
|
|
|
$this->mailer->addAddress($this->recipient);
|
|
|
|
$this->mailer->addReplyTo($this->replyto);
|
|
|
|
|
|
|
|
$this->mailer->isHTML(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $fqm
|
|
|
|
*/
|
|
|
|
public function setFullyQualifiedAddress($fqm)
|
|
|
|
{
|
|
|
|
$this->fqm = $fqm;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $from
|
|
|
|
*/
|
2019-09-15 20:27:26 +02:00
|
|
|
public function setFrom($from, $fromName)
|
2019-09-15 18:08:44 +01:00
|
|
|
{
|
|
|
|
$this->from = $from;
|
2019-09-15 20:27:26 +02:00
|
|
|
$this->fromName = $fromName;
|
2019-09-15 18:08:44 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $host
|
|
|
|
*/
|
|
|
|
public function setHost($host)
|
|
|
|
{
|
|
|
|
$this->host = $host;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $protocol
|
|
|
|
*/
|
|
|
|
public function setProtocol($protocol)
|
|
|
|
{
|
|
|
|
$this->protocol = $protocol;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $recipient
|
|
|
|
*/
|
|
|
|
public function setRecipient($recipient)
|
|
|
|
{
|
|
|
|
$this->recipient = $recipient;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $replyto
|
|
|
|
*/
|
|
|
|
public function setReplyto($replyto)
|
|
|
|
{
|
|
|
|
$this->replyto = $replyto;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setAuthPassword($authpassword)
|
|
|
|
{
|
|
|
|
$this->authpassword = $authpassword;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function send($subject, $content)
|
|
|
|
{
|
|
|
|
$this->mailer->Subject = $subject;
|
|
|
|
$this->mailer->Body = $content;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$this->mailer->send();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (\Exception $ex)
|
|
|
|
{
|
|
|
|
echo "Could not send email! " . $ex->getMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|