Modifications
This commit is contained in:
parent
4bad426149
commit
4a3ecb3a61
|
@ -39,7 +39,6 @@ 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)
|
||||||
|
@ -51,21 +50,40 @@ class BluescaleMailApi
|
||||||
$template->recipients[] = [
|
$template->recipients[] = [
|
||||||
'address' => $notifiable->email
|
'address' => $notifiable->email
|
||||||
];
|
];
|
||||||
|
}
|
||||||
|
|
||||||
if (count($attachments) > 0) {
|
$attachments = $template->attachments;
|
||||||
|
if (count($attachments) > 0) { // Formatting attachments to UploadFiles
|
||||||
$formatted_attachmments = [];
|
$formatted_attachmments = [];
|
||||||
foreach ($attachments as $attachment) {
|
foreach ($attachments as $attachment) {
|
||||||
$file = new UploadedFile($attachment['path'], $attachment['filename'], 'application/octet-stream', null, null, false);
|
$formatted_attachmments[] = new UploadedFile($attachment['path'], $attachment['filename'], null, null, false);
|
||||||
$formatted_attachmments[] = $file;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$template->attachments = $formatted_attachmments;
|
$template->attachments = $formatted_attachmments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$multipart_form = [];
|
||||||
|
|
||||||
|
foreach($template as $key => $value){ // Formatting whole template to pass in 'multipart' form
|
||||||
|
if(!is_array($value)){
|
||||||
|
$multipart_form[] = ['name' => $key, 'contents' => $value];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($value as $multiKey => $multiValue){
|
||||||
|
$multiName = $key . '[' .$multiKey . ']' . (is_array($multiValue) ? '[' . key($multiValue) . ']' : '' ) . '';
|
||||||
|
$data = ['name' => $multiName, 'contents' => (is_array($multiValue) ? reset($multiValue) : $multiValue)];
|
||||||
|
|
||||||
|
if (substr($key, 0, 11) === "attachments")
|
||||||
|
$data['filename'] = $multiValue->getClientOriginalName();
|
||||||
|
|
||||||
|
$multipart_form[] = $data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return $client->request('post', $url, [
|
return $client->request('post', $url, [
|
||||||
'form_params' => $template,
|
'multipart' => $multipart_form,
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'Authorization' => 'Bearer ' . $this->api_key,
|
'Authorization' => 'Bearer ' . $this->api_key,
|
||||||
'Accept' => 'application/json'
|
'Accept' => 'application/json'
|
||||||
|
|
Loading…
Reference in New Issue