/** * Attach a file to the message. * * @param string $path * @param string $name * * @return \Bogardo\Mailgun\Mail\Message */ public function attach($path, $name = '') { $this->messageBuilder->addAttachment($path, $name); return $this; }
/** * @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]); } }