Skip to content

Commit

Permalink
FIX Do not send text or html with null values
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellibonati committed Feb 16, 2024
1 parent d7be040 commit a8bb40a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Transaccional/Helpers/Builder/MailParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ public function toArray(): array
throw new ESTRException('Email address "To" must be set');
}

if (is_null($this->template_id) && is_null($this->text) && is_null($this->html)) {
throw new ESTRException(
"No content was provided. \n
Please set either the text or html attributes, or specify a template ID"
);
}

if (isset($this->template_id) && (isset($this->text) || isset($this->html))) {
throw new ESTRException('Content (html or text) and templates are mutually exclusive');
}
Expand Down Expand Up @@ -260,8 +267,13 @@ public function toArray(): array
if (!is_null($this->template_id)) {
$result['templateID'] = $this->template_id;
} else {
$result['html'] = $this->html;
$result['text'] = $this->text;
if (!is_null($this->html)) {
$result['html'] = $this->html;
}

if (!is_null($this->text)) {
$result['text'] = $this->text;
}
}

return array_merge($result, [
Expand Down

0 comments on commit a8bb40a

Please sign in to comment.