/** * Add a blind carbon copy to the message. * * @param string|array $address * @param string $name * @param array $variables * * @return \Bogardo\Mailgun\Mail\Message */ public function bcc($address, $name = "", array $variables = []) { if (!empty($variables)) { $this->variables[$address] = $variables; } $this->messageBuilder->addBccRecipient($address, ['full_name' => $name]); return $this; }
/** * @return MessageBuilder */ public static function getValid() { $message = new MessageBuilder(); $message->setFromAddress(MailWrapperTestBootstrap::$from); $message->addToRecipient(MailWrapperTestBootstrap::$toAddresses[0]); $message->addToRecipient(MailWrapperTestBootstrap::$toAddresses[1]); $message->addCcRecipient(MailWrapperTestBootstrap::$ccAddresses[0]); $message->addCcRecipient(MailWrapperTestBootstrap::$ccAddresses[1]); $message->addBccRecipient(MailWrapperTestBootstrap::$bccAddresses[0]); $message->addBccRecipient(MailWrapperTestBootstrap::$bccAddresses[1]); $message->setReplyToAddress(MailWrapperTestBootstrap::$alternate); $message->setSubject(MailWrapperTestBootstrap::$subject); $message->setTextBody(MailWrapperTestBootstrap::$contentText); $message->setHtmlBody(MailWrapperTestBootstrap::$contentHtml); return $message; }
/** * @param array $message * * @return \Mailgun\Messages\MessageBuilder * @throws \Mailgun\Messages\Exceptions\TooManyParameters */ protected function createMailgunMessage(array $message) { $builder = new MessageBuilder(); $builder->setFromAddress($message['from']); $builder->setSubject($message['subject']); foreach ($message['to'] as $to) { $builder->addToRecipient($to); } foreach ($message['cc'] as $cc) { $builder->addCcRecipient($cc); } foreach ($message['bcc'] as $bcc) { $builder->addBccRecipient($bcc); } if ($message['html']) { $builder->setHtmlBody($message['html']); } if ($message['text']) { $builder->setTextBody($message['text']); } return $builder; }
/** * @param MessageBuilder $builder * @param string $to * @param string $from * @param string $subject * @param string $content * @param string $plainContent * @param array $attachments * @param array $headers */ protected function buildMessage(MessageBuilder $builder, $to, $from, $subject, $content, $plainContent, array $attachments, array $headers) { // Add base info $parsedFrom = $this->parseAddresses($from); foreach ($parsedFrom as $email => $name) { $builder->setFromAddress($email, ['full_name' => $name]); } $builder->setSubject($subject); $builder->setHtmlBody($content); $builder->setTextBody($plainContent); // Add attachments foreach ($attachments as $attachment) { $builder->addAttachment($attachment['filePath'], $attachment['remoteName']); } // Parse Cc & Bcc headers out if they're set $ccAddresses = isset($headers['Cc']) ? $headers['Cc'] : ''; $bccAddresses = isset($headers['Bcc']) ? $headers['Bcc'] : ''; // We handle these ourselves, so can remove them from the list of headers unset($headers['Cc']); unset($headers['Bcc']); // Add remaining custom headers foreach ($headers as $name => $data) { $builder->addCustomHeader($name, $data); } // Add recipients. This is done last as the 'BatchMessage' message builder // will trigger sends for every 1000 addresses $to = $this->parseAddresses($to); foreach ($to as $email => $name) { $builder->addToRecipient($email, ['full_name' => $name]); } $ccAddresses = $this->parseAddresses($ccAddresses); foreach ($ccAddresses as $email => $name) { $builder->addCcRecipient($email, ['full_name' => $name]); } $bccAddresses = $this->parseAddresses($bccAddresses); foreach ($bccAddresses as $email => $name) { $builder->addBccRecipient($email, ['full_name' => $name]); } }