Example #1
0
 /**
  *
  * @param Envelope $envelope
  * @return PHPMailerOverride
  */
 protected function prepareMailer(Envelope $envelope)
 {
     $mail = new PHPMailerOverride(true);
     // the true param means it will throw exceptions on errors, which we need to catch
     $mail->Subject = FromUTF8::toIso88591Email($envelope->getSubject());
     $mail->CharSet = "utf-8";
     if ($envelope->isHtml()) {
         $mail->msgHTML($envelope->getBody());
     } else {
         $mail->Body = $envelope->getBodyText();
     }
     $mail->isSMTP();
     // telling the class to use SMTP
     if ($this->connection->getProtocol() != "smtp") {
         $mail->SMTPSecure = $this->connection->getProtocol();
         // ssl ou tls!
     }
     $replyTo = Util::decomposeEmail($envelope->getReplyTo());
     $mail->addReplyTo($replyTo["email"], $replyTo["name"]);
     // Define From email
     $from = Util::decomposeEmail($envelope->getFrom());
     $mail->setFrom($from["email"], $from["name"]);
     // Add Recipients
     foreach ((array) $envelope->getTo() as $toItem) {
         $to = Util::decomposeEmail($toItem);
         $mail->addAddress($to["email"], $to["name"]);
     }
     // Add Carbon Copy
     foreach ((array) $envelope->getCC() as $ccItem) {
         $cc = Util::decomposeEmail($ccItem);
         $mail->addCC($cc["email"], $cc["name"]);
     }
     // Add Blind Carbon Copy
     foreach ((array) $envelope->getBCC() as $bccItem) {
         $bcc = Util::decomposeEmail($bccItem);
         $mail->addBCC($bcc["email"], $bcc["name"]);
     }
     // Attachments
     foreach ((array) $envelope->getAttachments() as $name => $value) {
         $mail->addAttachment($value['content'], $name, 'base64', $value['content-type']);
     }
     return $mail;
 }
Example #2
0
 /**
  *
  * @param MailConnection $connection
  * @return MailWrapperInterface
  * @throws InvalidArgumentException
  */
 public static function mailerFactory(MailConnection $connection)
 {
     $protocol = $connection->getProtocol();
     if (in_array($protocol, ['smtp', 'ssl', 'tls'])) {
         $mail = new PHPMailerWrapper($connection);
     } elseif ($protocol === "ses") {
         $mail = new AmazonSesWrapper($connection);
     } elseif ($protocol === "mandrill") {
         $mail = new MandrillApiWrapper($connection);
     } elseif ($protocol === "sendmail") {
         $mail = new SendMailWrapper($connection);
     } elseif ($protocol === "mailgun") {
         $mail = new MailgunApiWrapper($connection);
     } else {
         throw new InvalidArgumentException("Connection '" . $connection->getProtocol() . "' is not valid");
     }
     return $mail;
 }