. */ /** * An extension to PHPMailer to set some defaults */ class Mailer extends PHPMailer { /** * {@inheritDoc} * * @param PDO $_pdo A PDO instance for database connection * @param mixed $exceptions For PHPMailer::__construct() */ public function __construct($_pdo, $exceptions = null) { parent::__construct($exceptions); $this->pdo = $_pdo; $this->isSMTP(); $this->Host = SMTP_HOST; $this->SMTPAuth = SMTP_AUTH; $this->Username = SMTP_USERNAME; $this->Password = SMTP_PASSWORD; $this->SMTPSecure = SMTP_SECURE; $this->Port = SMTP_PORT; if (defined('SMTP_OPTIONS')) $this->SMTPOptions = json_decode(SMTP_OPTIONS, true); $from = explode(';', MAILER_FROM); $this->setFrom($from[0], $from[1]); if (defined('MAILER_REPLY_TO')) { $replyto = explode(';', MAILER_REPLY_TO); $this->addReplyTo($replyto[0], $replyto[1]); } if (defined('MAILER_CC')) foreach (explode(';', MAILER_CC) as $cc) $this->addCC($cc); if (defined('MAILER_BCC')) foreach (explode(';', MAILER_BCC) as $bcc) $this->addBCC($bcc); } /** * Set the contact this mail should be sent to * * @param Contact $contact The contact */ public function setContact($contact) { $this->addAddress($contact->email, $contact->name); $this->contactId = $contact->id; } /** * Set the offer this email is about * * @param Offer $offer The offer */ public function setOffer($offer) { $this->setContact($offer->getContact()); $this->offerId = $offer->id; } /** * {@inheritDoc} * * Then store it in the database. */ public function send() { if (!parent::send()) { return false; } BusinessAdmin::createMail($this->pdo, $this->contactId, $this->offerId, $this->Subject); return true; } }