127 lines
2.3 KiB
PHP
127 lines
2.3 KiB
PHP
|
<?php
|
||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||
|
use PHPMailer\PHPMailer\Exception;
|
||
|
|
||
|
|
||
|
class MailWrapper
|
||
|
{
|
||
|
|
||
|
private $fqm, $host, $protocol, $replyto, $from;
|
||
|
|
||
|
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';
|
||
|
|
||
|
$this->mailer->setFrom($this->from);
|
||
|
$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
|
||
|
*/
|
||
|
public function setFrom($from)
|
||
|
{
|
||
|
$this->from = $from;
|
||
|
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();
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|