aboutsummaryrefslogtreecommitdiffhomepage
path: root/main/app/sprinkles/core/src/Mail
diff options
context:
space:
mode:
authorMarvin Borner2018-06-08 20:03:25 +0200
committerMarvin Borner2018-06-08 20:03:25 +0200
commit92b7dd3335a6572debeacfb5faa82c63a5e67888 (patch)
tree7ebbca22595d542ec5e2912a24a0400ac8f6b113 /main/app/sprinkles/core/src/Mail
parent22a1bb27f94ea33042b0bdd35bef1a5cfa96cc0d (diff)
Some minor fixes
Diffstat (limited to 'main/app/sprinkles/core/src/Mail')
-rw-r--r--main/app/sprinkles/core/src/Mail/EmailRecipient.php258
-rw-r--r--main/app/sprinkles/core/src/Mail/MailMessage.php350
-rw-r--r--main/app/sprinkles/core/src/Mail/Mailer.php400
-rw-r--r--main/app/sprinkles/core/src/Mail/StaticMailMessage.php148
-rw-r--r--main/app/sprinkles/core/src/Mail/TwigMailMessage.php178
5 files changed, 667 insertions, 667 deletions
diff --git a/main/app/sprinkles/core/src/Mail/EmailRecipient.php b/main/app/sprinkles/core/src/Mail/EmailRecipient.php
index 33b7db7..29b5de8 100644
--- a/main/app/sprinkles/core/src/Mail/EmailRecipient.php
+++ b/main/app/sprinkles/core/src/Mail/EmailRecipient.php
@@ -1,129 +1,129 @@
-<?php
-/**
- * UserFrosting (http://www.userfrosting.com)
- *
- * @link https://github.com/userfrosting/UserFrosting
- * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
- */
-
-namespace UserFrosting\Sprinkle\Core\Mail;
-
-/**
- * EmailRecipient Class
- *
- * A class representing a recipient for a MailMessage, with associated parameters.
- *
- * @author Alex Weissman (https://alexanderweissman.com)
- */
-class EmailRecipient
-{
-
- /**
- * @var string The email address for this recipient.
- */
- protected $email;
-
- /**
- * @var string The name for this recipient.
- */
- protected $name;
-
- /**
- * @var array Any additional parameters (name => value) to use when rendering an email template for this recipient.
- */
- protected $params = [];
-
- /**
- * @var array A list of CCs for this recipient. Each CC is an associative array with `email` and `name` properties.
- */
- protected $cc = [];
-
- /**
- * @var array A list of BCCs for this recipient. Each BCC is an associative array with `email` and `name` properties.
- */
- protected $bcc = [];
-
- /**
- * Create a new EmailRecipient instance.
- *
- * @param string $email The primary recipient email address.
- * @param string $name The primary recipient name.
- * @param array $params An array of template parameters to render the email message with for this particular recipient.
- */
- public function __construct($email, $name = "", $params = []) {
- $this->email = $email;
- $this->name = $name;
- $this->params = $params;
- }
-
- /**
- * Add a CC for this primary recipient.
- *
- * @param string $email The CC recipient email address.
- * @param string $name The CC recipient name.
- */
- public function cc($email, $name = "") {
- $this->cc[] = [
- "email" => $email,
- "name" => $name
- ];
- }
-
- /**
- * Add a BCC for this primary recipient.
- *
- * @param string $email The BCC recipient email address.
- * @param string $name The BCC recipient name.
- */
- public function bcc($email, $name = "") {
- $this->bcc[] = [
- "email" => $email,
- "name" => $name
- ];
- }
-
- /**
- * Get the primary recipient email address.
- *
- * @return string the primary recipient email address.
- */
- public function getEmail() {
- return $this->email;
- }
-
- /**
- * Get the primary recipient name.
- *
- * @return string the primary recipient name.
- */
- public function getName() {
- return $this->name;
- }
-
- /**
- * Get the parameters to use when rendering the template this recipient.
- *
- * @return array The parameters (name => value) to use when rendering an email template for this recipient.
- */
- public function getParams() {
- return $this->params;
- }
-
- /**
- * Get the list of CCs for this recipient.
- *
- * @return array A list of CCs for this recipient. Each CC is an associative array with `email` and `name` properties.
- */
- public function getCCs() {
- return $this->cc;
- }
-
- /**
- * Get the list of BCCs for this recipient.
- *
- * @return array A list of BCCs for this recipient. Each BCC is an associative array with `email` and `name` properties.
- */
- public function getBCCs() {
- return $this->bcc;
- }
-}
+<?php
+/**
+ * UserFrosting (http://www.userfrosting.com)
+ *
+ * @link https://github.com/userfrosting/UserFrosting
+ * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
+ */
+
+namespace UserFrosting\Sprinkle\Core\Mail;
+
+/**
+ * EmailRecipient Class
+ *
+ * A class representing a recipient for a MailMessage, with associated parameters.
+ *
+ * @author Alex Weissman (https://alexanderweissman.com)
+ */
+class EmailRecipient
+{
+
+ /**
+ * @var string The email address for this recipient.
+ */
+ protected $email;
+
+ /**
+ * @var string The name for this recipient.
+ */
+ protected $name;
+
+ /**
+ * @var array Any additional parameters (name => value) to use when rendering an email template for this recipient.
+ */
+ protected $params = [];
+
+ /**
+ * @var array A list of CCs for this recipient. Each CC is an associative array with `email` and `name` properties.
+ */
+ protected $cc = [];
+
+ /**
+ * @var array A list of BCCs for this recipient. Each BCC is an associative array with `email` and `name` properties.
+ */
+ protected $bcc = [];
+
+ /**
+ * Create a new EmailRecipient instance.
+ *
+ * @param string $email The primary recipient email address.
+ * @param string $name The primary recipient name.
+ * @param array $params An array of template parameters to render the email message with for this particular recipient.
+ */
+ public function __construct($email, $name = "", $params = []) {
+ $this->email = $email;
+ $this->name = $name;
+ $this->params = $params;
+ }
+
+ /**
+ * Add a CC for this primary recipient.
+ *
+ * @param string $email The CC recipient email address.
+ * @param string $name The CC recipient name.
+ */
+ public function cc($email, $name = "") {
+ $this->cc[] = [
+ "email" => $email,
+ "name" => $name
+ ];
+ }
+
+ /**
+ * Add a BCC for this primary recipient.
+ *
+ * @param string $email The BCC recipient email address.
+ * @param string $name The BCC recipient name.
+ */
+ public function bcc($email, $name = "") {
+ $this->bcc[] = [
+ "email" => $email,
+ "name" => $name
+ ];
+ }
+
+ /**
+ * Get the primary recipient email address.
+ *
+ * @return string the primary recipient email address.
+ */
+ public function getEmail() {
+ return $this->email;
+ }
+
+ /**
+ * Get the primary recipient name.
+ *
+ * @return string the primary recipient name.
+ */
+ public function getName() {
+ return $this->name;
+ }
+
+ /**
+ * Get the parameters to use when rendering the template this recipient.
+ *
+ * @return array The parameters (name => value) to use when rendering an email template for this recipient.
+ */
+ public function getParams() {
+ return $this->params;
+ }
+
+ /**
+ * Get the list of CCs for this recipient.
+ *
+ * @return array A list of CCs for this recipient. Each CC is an associative array with `email` and `name` properties.
+ */
+ public function getCCs() {
+ return $this->cc;
+ }
+
+ /**
+ * Get the list of BCCs for this recipient.
+ *
+ * @return array A list of BCCs for this recipient. Each BCC is an associative array with `email` and `name` properties.
+ */
+ public function getBCCs() {
+ return $this->bcc;
+ }
+}
diff --git a/main/app/sprinkles/core/src/Mail/MailMessage.php b/main/app/sprinkles/core/src/Mail/MailMessage.php
index 6aea56d..c16d1ad 100644
--- a/main/app/sprinkles/core/src/Mail/MailMessage.php
+++ b/main/app/sprinkles/core/src/Mail/MailMessage.php
@@ -1,175 +1,175 @@
-<?php
-/**
- * UserFrosting (http://www.userfrosting.com)
- *
- * @link https://github.com/userfrosting/UserFrosting
- * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
- */
-
-namespace UserFrosting\Sprinkle\Core\Mail;
-
-/**
- * MailMessage Class
- *
- * Represents a basic mail message, containing a static subject and body.
- *
- * @author Alex Weissman (https://alexanderweissman.com)
- */
-abstract class MailMessage
-{
- /**
- * @var string The current sender email address.
- */
- protected $fromEmail = "";
-
- /**
- * @var string The current sender name.
- */
- protected $fromName = NULL;
-
- /**
- * @var EmailRecipient[] A list of recipients for this message.
- */
- protected $recipients = [];
-
- /**
- * @var string The current reply-to email.
- */
- protected $replyEmail = NULL;
-
- /**
- * @var string The current reply-to name.
- */
- protected $replyName = NULL;
-
- /**
- * Gets the fully rendered text of the message body.
- *
- * @return string
- */
- abstract public function renderBody($params = []);
-
- /**
- * Gets the fully rendered text of the message subject.
- *
- * @return string
- */
- abstract public function renderSubject($params = []);
-
- /**
- * Add an email recipient.
- *
- * @param EmailRecipient $recipient
- */
- public function addEmailRecipient(EmailRecipient $recipient) {
- $this->recipients[] = $recipient;
- return $this;
- }
-
- /**
- * Clears out all recipients for this message.
- */
- public function clearRecipients() {
- $this->recipients = array();
- }
-
- /**
- * Set sender information for this message.
- *
- * This is a shortcut for calling setFromEmail, setFromName, setReplyEmail, and setReplyName.
- * @param string $fromInfo An array containing 'email', 'name', 'reply_email', and 'reply_name'.
- */
- public function from($fromInfo = []) {
- $this->setFromEmail(isset($fromInfo['email']) ? $fromInfo['email'] : "");
- $this->setFromName(isset($fromInfo['name']) ? $fromInfo['name'] : NULL);
- $this->setReplyEmail(isset($fromInfo['reply_email']) ? $fromInfo['reply_email'] : NULL);
- $this->setReplyName(isset($fromInfo['reply_name']) ? $fromInfo['reply_name'] : NULL);
-
- return $this;
- }
-
- /**
- * Get the sender email address.
- *
- * @return string
- */
- public function getFromEmail() {
- return $this->fromEmail;
- }
-
- /**
- * Get the sender name. Defaults to the email address if name is not set.
- *
- * @return string
- */
- public function getFromName() {
- return isset($this->fromName) ? $this->fromName : $this->getFromEmail();
- }
-
- /**
- * Get the list of recipients for this message.
- *
- * @return EmailRecipient[]
- */
- public function getRecipients() {
- return $this->recipients;
- }
-
- /**
- * Get the 'reply-to' address for this message. Defaults to the sender email.
- *
- * @return string
- */
- public function getReplyEmail() {
- return isset($this->replyEmail) ? $this->replyEmail : $this->getFromEmail();
- }
-
- /**
- * Get the 'reply-to' name for this message. Defaults to the sender name.
- *
- * @return string
- */
- public function getReplyName() {
- return isset($this->replyName) ? $this->replyName : $this->getFromName();
- }
-
- /**
- * Set the sender email address.
- *
- * @param string $fromEmail
- */
- public function setFromEmail($fromEmail) {
- $this->fromEmail = $fromEmail;
- return $this;
- }
-
- /**
- * Set the sender name.
- *
- * @param string $fromName
- */
- public function setFromName($fromName) {
- $this->fromName = $fromName;
- return $this;
- }
-
- /**
- * Set the sender 'reply-to' address.
- *
- * @param string $replyEmail
- */
- public function setReplyEmail($replyEmail) {
- $this->replyEmail = $replyEmail;
- return $this;
- }
-
- /**
- * Set the sender 'reply-to' name.
- *
- * @param string $replyName
- */
- public function setReplyName($replyName) {
- $this->replyName = $replyName;
- return $this;
- }
-}
+<?php
+/**
+ * UserFrosting (http://www.userfrosting.com)
+ *
+ * @link https://github.com/userfrosting/UserFrosting
+ * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
+ */
+
+namespace UserFrosting\Sprinkle\Core\Mail;
+
+/**
+ * MailMessage Class
+ *
+ * Represents a basic mail message, containing a static subject and body.
+ *
+ * @author Alex Weissman (https://alexanderweissman.com)
+ */
+abstract class MailMessage
+{
+ /**
+ * @var string The current sender email address.
+ */
+ protected $fromEmail = "";
+
+ /**
+ * @var string The current sender name.
+ */
+ protected $fromName = NULL;
+
+ /**
+ * @var EmailRecipient[] A list of recipients for this message.
+ */
+ protected $recipients = [];
+
+ /**
+ * @var string The current reply-to email.
+ */
+ protected $replyEmail = NULL;
+
+ /**
+ * @var string The current reply-to name.
+ */
+ protected $replyName = NULL;
+
+ /**
+ * Gets the fully rendered text of the message body.
+ *
+ * @return string
+ */
+ abstract public function renderBody($params = []);
+
+ /**
+ * Gets the fully rendered text of the message subject.
+ *
+ * @return string
+ */
+ abstract public function renderSubject($params = []);
+
+ /**
+ * Add an email recipient.
+ *
+ * @param EmailRecipient $recipient
+ */
+ public function addEmailRecipient(EmailRecipient $recipient) {
+ $this->recipients[] = $recipient;
+ return $this;
+ }
+
+ /**
+ * Clears out all recipients for this message.
+ */
+ public function clearRecipients() {
+ $this->recipients = array();
+ }
+
+ /**
+ * Set sender information for this message.
+ *
+ * This is a shortcut for calling setFromEmail, setFromName, setReplyEmail, and setReplyName.
+ * @param string $fromInfo An array containing 'email', 'name', 'reply_email', and 'reply_name'.
+ */
+ public function from($fromInfo = []) {
+ $this->setFromEmail(isset($fromInfo['email']) ? $fromInfo['email'] : "");
+ $this->setFromName(isset($fromInfo['name']) ? $fromInfo['name'] : NULL);
+ $this->setReplyEmail(isset($fromInfo['reply_email']) ? $fromInfo['reply_email'] : NULL);
+ $this->setReplyName(isset($fromInfo['reply_name']) ? $fromInfo['reply_name'] : NULL);
+
+ return $this;
+ }
+
+ /**
+ * Get the sender email address.
+ *
+ * @return string
+ */
+ public function getFromEmail() {
+ return $this->fromEmail;
+ }
+
+ /**
+ * Get the sender name. Defaults to the email address if name is not set.
+ *
+ * @return string
+ */
+ public function getFromName() {
+ return isset($this->fromName) ? $this->fromName : $this->getFromEmail();
+ }
+
+ /**
+ * Get the list of recipients for this message.
+ *
+ * @return EmailRecipient[]
+ */
+ public function getRecipients() {
+ return $this->recipients;
+ }
+
+ /**
+ * Get the 'reply-to' address for this message. Defaults to the sender email.
+ *
+ * @return string
+ */
+ public function getReplyEmail() {
+ return isset($this->replyEmail) ? $this->replyEmail : $this->getFromEmail();
+ }
+
+ /**
+ * Get the 'reply-to' name for this message. Defaults to the sender name.
+ *
+ * @return string
+ */
+ public function getReplyName() {
+ return isset($this->replyName) ? $this->replyName : $this->getFromName();
+ }
+
+ /**
+ * Set the sender email address.
+ *
+ * @param string $fromEmail
+ */
+ public function setFromEmail($fromEmail) {
+ $this->fromEmail = $fromEmail;
+ return $this;
+ }
+
+ /**
+ * Set the sender name.
+ *
+ * @param string $fromName
+ */
+ public function setFromName($fromName) {
+ $this->fromName = $fromName;
+ return $this;
+ }
+
+ /**
+ * Set the sender 'reply-to' address.
+ *
+ * @param string $replyEmail
+ */
+ public function setReplyEmail($replyEmail) {
+ $this->replyEmail = $replyEmail;
+ return $this;
+ }
+
+ /**
+ * Set the sender 'reply-to' name.
+ *
+ * @param string $replyName
+ */
+ public function setReplyName($replyName) {
+ $this->replyName = $replyName;
+ return $this;
+ }
+}
diff --git a/main/app/sprinkles/core/src/Mail/Mailer.php b/main/app/sprinkles/core/src/Mail/Mailer.php
index 761d15a..5331107 100644
--- a/main/app/sprinkles/core/src/Mail/Mailer.php
+++ b/main/app/sprinkles/core/src/Mail/Mailer.php
@@ -1,200 +1,200 @@
-<?php
-/**
- * UserFrosting (http://www.userfrosting.com)
- *
- * @link https://github.com/userfrosting/UserFrosting
- * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
- */
-
-namespace UserFrosting\Sprinkle\Core\Mail;
-
-use Monolog\Logger;
-
-/**
- * Mailer Class
- *
- * A basic wrapper for sending template-based emails.
- *
- * @author Alex Weissman (https://alexanderweissman.com)
- */
-class Mailer
-{
- /**
- * @var Logger
- */
- protected $logger;
-
- /**
- * @var \PHPMailer
- */
- protected $phpMailer;
-
- /**
- * Create a new Mailer instance.
- *
- * @param Logger $logger A Monolog logger, used to dump debugging info for SMTP server transactions.
- * @param mixed[] $config An array of configuration parameters for phpMailer.
- * @throws \phpmailerException Wrong mailer config value given.
- */
- public function __construct($logger, $config = []) {
- $this->logger = $logger;
-
- // 'true' tells PHPMailer to use exceptions instead of error codes
- $this->phpMailer = new \PHPMailer(TRUE);
-
- // Configuration options
- if (isset($config['mailer'])) {
- if (!in_array($config['mailer'], ['smtp', 'mail', 'qmail', 'sendmail'])) {
- throw new \phpmailerException("'mailer' must be one of 'smtp', 'mail', 'qmail', or 'sendmail'.");
- }
-
- if ($config['mailer'] == 'smtp') {
- $this->phpMailer->isSMTP(TRUE);
- $this->phpMailer->Host = $config['host'];
- $this->phpMailer->Port = $config['port'];
- $this->phpMailer->SMTPAuth = $config['auth'];
- $this->phpMailer->SMTPSecure = $config['secure'];
- $this->phpMailer->Username = $config['username'];
- $this->phpMailer->Password = $config['password'];
- $this->phpMailer->SMTPDebug = $config['smtp_debug'];
-
- if (isset($config['smtp_options'])) {
- $this->phpMailer->SMTPOptions = $config['smtp_options'];
- }
- }
-
- // Set any additional message-specific options
- // enforce which options can be set through this subarray
- if (isset($config['message_options'])) {
- $this->setOptions($config['message_options']);
- }
- }
-
- // Pass logger into phpMailer object
- $this->phpMailer->Debugoutput = function ($message, $level) {
- $this->logger->debug($message);
- };
- }
-
- /**
- * Get the underlying PHPMailer object.
- *
- * @return \PHPMailer
- */
- public function getPhpMailer() {
- return $this->phpMailer;
- }
-
- /**
- * Send a MailMessage message.
- *
- * Sends a single email to all recipients, as well as their CCs and BCCs.
- * Since it is a single-header message, recipient-specific template data will not be included.
- * @param MailMessage $message
- * @param bool $clearRecipients Set to true to clear the list of recipients in the message after calling send(). This helps avoid accidentally sending a message multiple times.
- * @throws \phpmailerException The message could not be sent.
- */
- public function send(MailMessage $message, $clearRecipients = TRUE) {
- $this->phpMailer->From = $message->getFromEmail();
- $this->phpMailer->FromName = $message->getFromName();
- $this->phpMailer->addReplyTo($message->getReplyEmail(), $message->getReplyName());
-
- // Add all email recipients, as well as their CCs and BCCs
- foreach ($message->getRecipients() as $recipient) {
- $this->phpMailer->addAddress($recipient->getEmail(), $recipient->getName());
-
- // Add any CCs and BCCs
- if ($recipient->getCCs()) {
- foreach ($recipient->getCCs() as $cc) {
- $this->phpMailer->addCC($cc['email'], $cc['name']);
- }
- }
-
- if ($recipient->getBCCs()) {
- foreach ($recipient->getBCCs() as $bcc) {
- $this->phpMailer->addBCC($bcc['email'], $bcc['name']);
- }
- }
- }
-
- $this->phpMailer->Subject = $message->renderSubject();
- $this->phpMailer->Body = $message->renderBody();
-
- // Try to send the mail. Will throw an exception on failure.
- $this->phpMailer->send();
-
- // Clear recipients from the PHPMailer object for this iteration,
- // so that we can use the same object for other emails.
- $this->phpMailer->clearAllRecipients();
-
- // Clear out the MailMessage's internal recipient list
- if ($clearRecipients) {
- $message->clearRecipients();
- }
- }
-
- /**
- * Send a MailMessage message, sending a separate email to each recipient.
- *
- * If the message object supports message templates, this will render the template with the corresponding placeholder values for each recipient.
- * @param MailMessage $message
- * @param bool $clearRecipients Set to true to clear the list of recipients in the message after calling send(). This helps avoid accidentally sending a message multiple times.
- * @throws \phpmailerException The message could not be sent.
- */
- public function sendDistinct(MailMessage $message, $clearRecipients = TRUE) {
- $this->phpMailer->From = $message->getFromEmail();
- $this->phpMailer->FromName = $message->getFromName();
- $this->phpMailer->addReplyTo($message->getReplyEmail(), $message->getReplyName());
-
- // Loop through email recipients, sending customized content to each one
- foreach ($message->getRecipients() as $recipient) {
- $this->phpMailer->addAddress($recipient->getEmail(), $recipient->getName());
-
- // Add any CCs and BCCs
- if ($recipient->getCCs()) {
- foreach ($recipient->getCCs() as $cc) {
- $this->phpMailer->addCC($cc['email'], $cc['name']);
- }
- }
-
- if ($recipient->getBCCs()) {
- foreach ($recipient->getBCCs() as $bcc) {
- $this->phpMailer->addBCC($bcc['email'], $bcc['name']);
- }
- }
-
- $this->phpMailer->Subject = $message->renderSubject($recipient->getParams());
- $this->phpMailer->Body = $message->renderBody($recipient->getParams());
-
- // Try to send the mail. Will throw an exception on failure.
- $this->phpMailer->send();
-
- // Clear recipients from the PHPMailer object for this iteration,
- // so that we can send a separate email to the next recipient.
- $this->phpMailer->clearAllRecipients();
- }
-
- // Clear out the MailMessage's internal recipient list
- if ($clearRecipients) {
- $message->clearRecipients();
- }
- }
-
- /**
- * Set option(s) on the underlying phpMailer object.
- *
- * @param mixed[] $options
- * @return Mailer
- */
- public function setOptions($options) {
- if (isset($options['isHtml'])) {
- $this->phpMailer->isHTML($options['isHtml']);
- }
-
- foreach ($options as $name => $value) {
- $this->phpMailer->set($name, $value);
- }
-
- return $this;
- }
-}
+<?php
+/**
+ * UserFrosting (http://www.userfrosting.com)
+ *
+ * @link https://github.com/userfrosting/UserFrosting
+ * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
+ */
+
+namespace UserFrosting\Sprinkle\Core\Mail;
+
+use Monolog\Logger;
+
+/**
+ * Mailer Class
+ *
+ * A basic wrapper for sending template-based emails.
+ *
+ * @author Alex Weissman (https://alexanderweissman.com)
+ */
+class Mailer
+{
+ /**
+ * @var Logger
+ */
+ protected $logger;
+
+ /**
+ * @var \PHPMailer
+ */
+ protected $phpMailer;
+
+ /**
+ * Create a new Mailer instance.
+ *
+ * @param Logger $logger A Monolog logger, used to dump debugging info for SMTP server transactions.
+ * @param mixed[] $config An array of configuration parameters for phpMailer.
+ * @throws \phpmailerException Wrong mailer config value given.
+ */
+ public function __construct($logger, $config = []) {
+ $this->logger = $logger;
+
+ // 'true' tells PHPMailer to use exceptions instead of error codes
+ $this->phpMailer = new \PHPMailer(TRUE);
+
+ // Configuration options
+ if (isset($config['mailer'])) {
+ if (!in_array($config['mailer'], ['smtp', 'mail', 'qmail', 'sendmail'])) {
+ throw new \phpmailerException("'mailer' must be one of 'smtp', 'mail', 'qmail', or 'sendmail'.");
+ }
+
+ if ($config['mailer'] == 'smtp') {
+ $this->phpMailer->isSMTP(TRUE);
+ $this->phpMailer->Host = $config['host'];
+ $this->phpMailer->Port = $config['port'];
+ $this->phpMailer->SMTPAuth = $config['auth'];
+ $this->phpMailer->SMTPSecure = $config['secure'];
+ $this->phpMailer->Username = $config['username'];
+ $this->phpMailer->Password = $config['password'];
+ $this->phpMailer->SMTPDebug = $config['smtp_debug'];
+
+ if (isset($config['smtp_options'])) {
+ $this->phpMailer->SMTPOptions = $config['smtp_options'];
+ }
+ }
+
+ // Set any additional message-specific options
+ // enforce which options can be set through this subarray
+ if (isset($config['message_options'])) {
+ $this->setOptions($config['message_options']);
+ }
+ }
+
+ // Pass logger into phpMailer object
+ $this->phpMailer->Debugoutput = function ($message, $level) {
+ $this->logger->debug($message);
+ };
+ }
+
+ /**
+ * Get the underlying PHPMailer object.
+ *
+ * @return \PHPMailer
+ */
+ public function getPhpMailer() {
+ return $this->phpMailer;
+ }
+
+ /**
+ * Send a MailMessage message.
+ *
+ * Sends a single email to all recipients, as well as their CCs and BCCs.
+ * Since it is a single-header message, recipient-specific template data will not be included.
+ * @param MailMessage $message
+ * @param bool $clearRecipients Set to true to clear the list of recipients in the message after calling send(). This helps avoid accidentally sending a message multiple times.
+ * @throws \phpmailerException The message could not be sent.
+ */
+ public function send(MailMessage $message, $clearRecipients = TRUE) {
+ $this->phpMailer->From = $message->getFromEmail();
+ $this->phpMailer->FromName = $message->getFromName();
+ $this->phpMailer->addReplyTo($message->getReplyEmail(), $message->getReplyName());
+
+ // Add all email recipients, as well as their CCs and BCCs
+ foreach ($message->getRecipients() as $recipient) {
+ $this->phpMailer->addAddress($recipient->getEmail(), $recipient->getName());
+
+ // Add any CCs and BCCs
+ if ($recipient->getCCs()) {
+ foreach ($recipient->getCCs() as $cc) {
+ $this->phpMailer->addCC($cc['email'], $cc['name']);
+ }
+ }
+
+ if ($recipient->getBCCs()) {
+ foreach ($recipient->getBCCs() as $bcc) {
+ $this->phpMailer->addBCC($bcc['email'], $bcc['name']);
+ }
+ }
+ }
+
+ $this->phpMailer->Subject = $message->renderSubject();
+ $this->phpMailer->Body = $message->renderBody();
+
+ // Try to send the mail. Will throw an exception on failure.
+ $this->phpMailer->send();
+
+ // Clear recipients from the PHPMailer object for this iteration,
+ // so that we can use the same object for other emails.
+ $this->phpMailer->clearAllRecipients();
+
+ // Clear out the MailMessage's internal recipient list
+ if ($clearRecipients) {
+ $message->clearRecipients();
+ }
+ }
+
+ /**
+ * Send a MailMessage message, sending a separate email to each recipient.
+ *
+ * If the message object supports message templates, this will render the template with the corresponding placeholder values for each recipient.
+ * @param MailMessage $message
+ * @param bool $clearRecipients Set to true to clear the list of recipients in the message after calling send(). This helps avoid accidentally sending a message multiple times.
+ * @throws \phpmailerException The message could not be sent.
+ */
+ public function sendDistinct(MailMessage $message, $clearRecipients = TRUE) {
+ $this->phpMailer->From = $message->getFromEmail();
+ $this->phpMailer->FromName = $message->getFromName();
+ $this->phpMailer->addReplyTo($message->getReplyEmail(), $message->getReplyName());
+
+ // Loop through email recipients, sending customized content to each one
+ foreach ($message->getRecipients() as $recipient) {
+ $this->phpMailer->addAddress($recipient->getEmail(), $recipient->getName());
+
+ // Add any CCs and BCCs
+ if ($recipient->getCCs()) {
+ foreach ($recipient->getCCs() as $cc) {
+ $this->phpMailer->addCC($cc['email'], $cc['name']);
+ }
+ }
+
+ if ($recipient->getBCCs()) {
+ foreach ($recipient->getBCCs() as $bcc) {
+ $this->phpMailer->addBCC($bcc['email'], $bcc['name']);
+ }
+ }
+
+ $this->phpMailer->Subject = $message->renderSubject($recipient->getParams());
+ $this->phpMailer->Body = $message->renderBody($recipient->getParams());
+
+ // Try to send the mail. Will throw an exception on failure.
+ $this->phpMailer->send();
+
+ // Clear recipients from the PHPMailer object for this iteration,
+ // so that we can send a separate email to the next recipient.
+ $this->phpMailer->clearAllRecipients();
+ }
+
+ // Clear out the MailMessage's internal recipient list
+ if ($clearRecipients) {
+ $message->clearRecipients();
+ }
+ }
+
+ /**
+ * Set option(s) on the underlying phpMailer object.
+ *
+ * @param mixed[] $options
+ * @return Mailer
+ */
+ public function setOptions($options) {
+ if (isset($options['isHtml'])) {
+ $this->phpMailer->isHTML($options['isHtml']);
+ }
+
+ foreach ($options as $name => $value) {
+ $this->phpMailer->set($name, $value);
+ }
+
+ return $this;
+ }
+}
diff --git a/main/app/sprinkles/core/src/Mail/StaticMailMessage.php b/main/app/sprinkles/core/src/Mail/StaticMailMessage.php
index 482226c..17758db 100644
--- a/main/app/sprinkles/core/src/Mail/StaticMailMessage.php
+++ b/main/app/sprinkles/core/src/Mail/StaticMailMessage.php
@@ -1,74 +1,74 @@
-<?php
-/**
- * UserFrosting (http://www.userfrosting.com)
- *
- * @link https://github.com/userfrosting/UserFrosting
- * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
- */
-
-namespace UserFrosting\Sprinkle\Core\Mail;
-
-/**
- * StaticMailMessage Class
- *
- * Represents a basic mail message, containing a static subject and body.
- *
- * @author Alex Weissman (https://alexanderweissman.com)
- */
-class StaticMailMessage extends MailMessage
-{
- /**
- * @var string The default body for this message.
- */
- protected $body;
-
- /**
- * @var string The default subject for this message.
- */
- protected $subject;
-
- /**
- * Create a new MailMessage instance.
- *
- * @param string $subject
- * @param string $body
- */
- public function __construct($subject = "", $body = "") {
- $this->subject = $subject;
- $this->body = $body;
- }
-
- /**
- * {@inheritDoc}
- */
- public function renderBody($params = []) {
- return $this->body;
- }
-
- /**
- * {@inheritDoc}
- */
- public function renderSubject($params = []) {
- return $this->subject;
- }
-
- /**
- * Set the text of the message subject.
- *
- * @param string $subject
- */
- public function setSubject($subject) {
- $this->subject = $subject;
- return $this;
- }
-
- /**
- * Set the text of the message body.
- *
- * @param string $body
- */
- public function setBody($body) {
- $this->body = $body;
- return $this;
- }
-}
+<?php
+/**
+ * UserFrosting (http://www.userfrosting.com)
+ *
+ * @link https://github.com/userfrosting/UserFrosting
+ * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
+ */
+
+namespace UserFrosting\Sprinkle\Core\Mail;
+
+/**
+ * StaticMailMessage Class
+ *
+ * Represents a basic mail message, containing a static subject and body.
+ *
+ * @author Alex Weissman (https://alexanderweissman.com)
+ */
+class StaticMailMessage extends MailMessage
+{
+ /**
+ * @var string The default body for this message.
+ */
+ protected $body;
+
+ /**
+ * @var string The default subject for this message.
+ */
+ protected $subject;
+
+ /**
+ * Create a new MailMessage instance.
+ *
+ * @param string $subject
+ * @param string $body
+ */
+ public function __construct($subject = "", $body = "") {
+ $this->subject = $subject;
+ $this->body = $body;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function renderBody($params = []) {
+ return $this->body;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function renderSubject($params = []) {
+ return $this->subject;
+ }
+
+ /**
+ * Set the text of the message subject.
+ *
+ * @param string $subject
+ */
+ public function setSubject($subject) {
+ $this->subject = $subject;
+ return $this;
+ }
+
+ /**
+ * Set the text of the message body.
+ *
+ * @param string $body
+ */
+ public function setBody($body) {
+ $this->body = $body;
+ return $this;
+ }
+}
diff --git a/main/app/sprinkles/core/src/Mail/TwigMailMessage.php b/main/app/sprinkles/core/src/Mail/TwigMailMessage.php
index aa4daea..7197f75 100644
--- a/main/app/sprinkles/core/src/Mail/TwigMailMessage.php
+++ b/main/app/sprinkles/core/src/Mail/TwigMailMessage.php
@@ -1,89 +1,89 @@
-<?php
-/**
- * UserFrosting (http://www.userfrosting.com)
- *
- * @link https://github.com/userfrosting/UserFrosting
- * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
- */
-
-namespace UserFrosting\Sprinkle\Core\Mail;
-
-/**
- * MailMessage Class
- *
- * Represents a basic mail message, containing a static subject and body.
- *
- * @author Alex Weissman (https://alexanderweissman.com)
- */
-class TwigMailMessage extends MailMessage
-{
- /**
- * @var mixed[] A list of Twig placeholder values to use when rendering this message.
- */
- protected $params;
-
- /**
- * @var Twig_Template The Twig template object, to source the content for this message.
- */
- protected $template;
-
- /**
- * @var \Slim\Views\Twig The view object, used to render mail templates.
- */
- protected $view;
-
- /**
- * Create a new TwigMailMessage instance.
- *
- * @param Slim\Views\Twig $view The Twig view object used to render mail templates.
- * @param string $filename optional Set the Twig template to use for this message.
- */
- public function __construct($view, $filename = NULL) {
- $this->view = $view;
-
- $twig = $this->view->getEnvironment();
- // Must manually merge in global variables for block rendering
- // should we keep this separate from the local parameters?
- $this->params = $twig->getGlobals();
-
- if ($filename !== NULL) {
- $this->template = $twig->loadTemplate($filename);
- }
- }
-
- /**
- * Merge in any additional global Twig variables to use when rendering this message.
- *
- * @param mixed[] $params
- */
- public function addParams($params = []) {
- $this->params = array_replace_recursive($this->params, $params);
- return $this;
- }
-
- /**
- * {@inheritDoc}
- */
- public function renderSubject($params = []) {
- $params = array_replace_recursive($this->params, $params);
- return $this->template->renderBlock('subject', $params);
- }
-
- /**
- * {@inheritDoc}
- */
- public function renderBody($params = []) {
- $params = array_replace_recursive($this->params, $params);
- return $this->template->renderBlock('body', $params);
- }
-
- /**
- * Sets the Twig template object for this message.
- *
- * @param Twig_Template $template The Twig template object, to source the content for this message.
- */
- public function setTemplate($template) {
- $this->template = $template;
- return $this;
- }
-}
+<?php
+/**
+ * UserFrosting (http://www.userfrosting.com)
+ *
+ * @link https://github.com/userfrosting/UserFrosting
+ * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
+ */
+
+namespace UserFrosting\Sprinkle\Core\Mail;
+
+/**
+ * MailMessage Class
+ *
+ * Represents a basic mail message, containing a static subject and body.
+ *
+ * @author Alex Weissman (https://alexanderweissman.com)
+ */
+class TwigMailMessage extends MailMessage
+{
+ /**
+ * @var mixed[] A list of Twig placeholder values to use when rendering this message.
+ */
+ protected $params;
+
+ /**
+ * @var Twig_Template The Twig template object, to source the content for this message.
+ */
+ protected $template;
+
+ /**
+ * @var \Slim\Views\Twig The view object, used to render mail templates.
+ */
+ protected $view;
+
+ /**
+ * Create a new TwigMailMessage instance.
+ *
+ * @param Slim\Views\Twig $view The Twig view object used to render mail templates.
+ * @param string $filename optional Set the Twig template to use for this message.
+ */
+ public function __construct($view, $filename = NULL) {
+ $this->view = $view;
+
+ $twig = $this->view->getEnvironment();
+ // Must manually merge in global variables for block rendering
+ // should we keep this separate from the local parameters?
+ $this->params = $twig->getGlobals();
+
+ if ($filename !== NULL) {
+ $this->template = $twig->loadTemplate($filename);
+ }
+ }
+
+ /**
+ * Merge in any additional global Twig variables to use when rendering this message.
+ *
+ * @param mixed[] $params
+ */
+ public function addParams($params = []) {
+ $this->params = array_replace_recursive($this->params, $params);
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function renderSubject($params = []) {
+ $params = array_replace_recursive($this->params, $params);
+ return $this->template->renderBlock('subject', $params);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function renderBody($params = []) {
+ $params = array_replace_recursive($this->params, $params);
+ return $this->template->renderBlock('body', $params);
+ }
+
+ /**
+ * Sets the Twig template object for this message.
+ *
+ * @param Twig_Template $template The Twig template object, to source the content for this message.
+ */
+ public function setTemplate($template) {
+ $this->template = $template;
+ return $this;
+ }
+}