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