=1) { return $this->sendPostmarkMail($toEmail, $fromEmail, $fromName, $replyEmail, $subject, $views, $data); } else { return $this->sendLaravelMail($toEmail, $fromEmail, $fromName, $replyEmail, $subject, $views, $data); } //return $this->sendPostmarkMail($toEmail, $fromEmail, $fromName, $replyEmail, $subject, $views, $data); } private function sendPostmarkMail($toEmail, $fromEmail, $fromName, $replyEmail, $subject, $views, $data = []) { $htmlBody = view($views[0], $data)->render(); $textBody = view($views[1], $data)->render(); $attachments = []; if (isset($data['account'])) { $account = $data['account']; $logoName = $account->getLogoName(); if (strpos($htmlBody, 'cid:' . $logoName) !== false && $account->hasLogo()) $attachments[] = PostmarkAttachment::fromFile($account->getLogoPath(), $logoName, null, 'cid:' . $logoName); } if (strpos($htmlBody, 'cid:invoiceninja-logo.png') !== false) { $attachments[] = PostmarkAttachment::fromFile(public_path('images/invoiceninja-logo.png'), 'invoiceninja-logo.png', null, 'cid:invoiceninja-logo.png'); //$attachments[] = PostmarkAttachment::fromFile(public_path('images/emails/icon-facebook.png'), 'icon-facebook.png', null, 'cid:icon-facebook.png'); //$attachments[] = PostmarkAttachment::fromFile(public_path('images/emails/icon-twitter.png'), 'icon-twitter.png', null, 'cid:icon-twitter.png'); //$attachments[] = PostmarkAttachment::fromFile(public_path('images/emails/icon-github.png'), 'icon-github.png', null, 'cid:icon-github.png'); } // Handle invoice attachments if (! empty($data['pdfString']) && ! empty($data['pdfFileName'])) $attachments[] = PostmarkAttachment::fromRawData($data['pdfString'], $data['pdfFileName']); if (! empty($data['ublString']) && ! empty($data['ublFileName'])) $attachments[] = PostmarkAttachment::fromRawData($data['ublString'], $data['ublFileName']); if (! empty($data['documents'])) { foreach ($data['documents'] as $document) $attachments[] = PostmarkAttachment::fromRawData($document['data'], $document['name']); } try { if (Utils::isNinjaProd()) $postmarkToken = Domain::getPostmarkTokenFromId($account->domain_id); else $postmarkToken = config('services.postmark_ticket'); $client = new PostmarkClient($postmarkToken); $message = [ 'To' => $toEmail, 'From' => sprintf('"%s" <%s>', addslashes($fromName), $fromEmail), 'ReplyTo' => $replyEmail, 'Subject' => $subject, 'TextBody' => $textBody, 'HtmlBody' => $htmlBody, 'Attachments' => $attachments, ]; if (! empty($data['bccEmail'])) $message['Bcc'] = $data['bccEmail']; if (! empty($data['tag'])) $message['Tag'] = $data['tag']; $response = $client->sendEmailBatch([$message]); if ($messageId = $response[0]->messageid) return $this->handleSuccess($data, $messageId); else return $this->handleFailure($data, $response[0]->message); } catch (PostmarkException $exception) { return $this->handleFailure($data, $exception->getMessage()); } catch (Exception $exception) { Utils::logError(Utils::getErrorString($exception)); throw $exception; } } /** * @param $response * @param $data * * @return bool */ private function handleSuccess($data, $messageId = false) { if (isset($data['invitation'])) { $invitation = $data['invitation']; if ($invitation) $invitation->markSent($messageId); } return true; } /** * @param $exception * * @return string */ private function handleFailure($data, $emailError) { if (isset($data['invitation'])) { $invitation = $data['invitation']; $invitation->email_error = $emailError; $invitation->save(); } elseif (! Utils::isNinjaProd()) Utils::logError($emailError); return $emailError; } }