feature/add-attachments #2
|
@ -37,6 +37,7 @@ class BluescaleMailApi
|
|||
$notifiable_recipient = false;
|
||||
$notifiable_email = $notifiable->email;
|
||||
$recipients = $template->recipients;
|
||||
$attachments = $template->attachments;
|
||||
|
||||
if (count($recipients) > 0)
|
||||
foreach ($recipients as $recipient)
|
||||
|
@ -44,17 +45,35 @@ class BluescaleMailApi
|
|||
if ($notifiable_email == $recipient['address'])
|
||||
$notifiable_recipient = true;
|
||||
|
||||
|
||||
if (!$notifiable_recipient)
|
||||
$template->recipients[] = [
|
||||
'address' => $notifiable->email
|
||||
];
|
||||
}
|
||||
$files = [];
|
||||
if (count($attachments) > 0)
|
||||
foreach ($attachments as $attachment)
|
||||
$files[] = [
|
||||
'name' => $attachment['name'],
|
||||
'contents' => $attachment['content'],
|
||||
'filename' => $attachment['filename'],
|
||||
];
|
||||
|
||||
try {
|
||||
return $client->request('post', $url, [
|
||||
'form_params' => $template,
|
||||
'headers' => [
|
||||
if (count($attachments) > 0) {
|
||||
return $client->request('post', $url, [
|
||||
'multipart' => $files,
|
||||
'form_params' => $template,
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . $this->api_key,
|
||||
'Accept' => 'application/json'
|
||||
]
|
||||
])->getBody();
|
||||
}
|
||||
|
||||
return $client->request('post', $url, [
|
||||
'form_params' => $template,
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . $this->api_key,
|
||||
'Accept' => 'application/json'
|
||||
]
|
||||
|
|
|
@ -26,6 +26,13 @@ class BluescaleMailTemplate implements \JsonSerializable
|
|||
public $recipients = [];
|
||||
|
||||
/**
|
||||
* The attachments for the message
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $attachments = [];
|
||||
|
||||
/**
|
||||
* The reply address for the message
|
||||
*
|
||||
* @var array
|
||||
|
@ -159,6 +166,7 @@ class BluescaleMailTemplate implements \JsonSerializable
|
|||
'sender' => $this->sender,
|
||||
'replyTo' => $this->replyTo,
|
||||
'recipients' => $this->recipients,
|
||||
'attachments' => $this->attachments,
|
||||
'parameters' => $this->parameters,
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue