Skip to content

Commit

Permalink
Merge pull request #2 from YieldStudio/feature/add-attachments
Browse files Browse the repository at this point in the history
Add attachments and make variables optional
  • Loading branch information
JamesHemery authored Mar 20, 2023
2 parents 1f4ce64 + 46b7384 commit 6f4ed59
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions src/MailjetEmailMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class MailjetEmailMessage

public array $variables = [];

public array $attachments = [];

public function templateId(int $templateId): static
{
$this->templateId = $templateId;
Expand Down Expand Up @@ -117,20 +119,43 @@ public function variable(string $key, $value): static
return $this;
}

public function attachments(array $attachments): static
{
$this->attachments = $attachments;

return $this;
}

public function attachment(array $attachment): static
{
$this->attachments[] = $attachment;

return $this;
}

public function toArray(): array
{
$messagesData = [
'To' => $this->to,
'Cc' => $this->cc,
'Bcc' => $this->bcc,
'From' => $this->from,
'TemplateID' => $this->templateId,
'TemplateLanguage' => $this->templateLanguage,
'Subject' => $this->subject,
];

if (filled($this->variables)) {
$messagesData['Variables'] = $this->variables;
}

if (filled($this->attachments)) {
$messagesData['Attachments'] = $this->attachments;
}

return [
'Messages' => [
[
'To' => $this->to,
'Cc' => $this->cc,
'Bcc' => $this->bcc,
'From' => $this->from,
'TemplateID' => $this->templateId,
'TemplateLanguage' => $this->templateLanguage,
'Subject' => $this->subject,
'Variables' => $this->variables,
],
$messagesData,
],
];
}
Expand Down

0 comments on commit 6f4ed59

Please sign in to comment.