Add files
This commit is contained in:
127
src/MailWrapper.php
Normal file
127
src/MailWrapper.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?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->SMTPDebug = 2;
|
||||
$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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user