From a8bb40a4a497089e7010297f5ea09b2117c2d376 Mon Sep 17 00:00:00 2001 From: Daniel Libonati Date: Fri, 16 Feb 2024 13:17:46 -0300 Subject: [PATCH] FIX Do not send text or html with null values --- src/Transaccional/Helpers/Builder/MailParams.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Transaccional/Helpers/Builder/MailParams.php b/src/Transaccional/Helpers/Builder/MailParams.php index e12c0b8..c94ce60 100644 --- a/src/Transaccional/Helpers/Builder/MailParams.php +++ b/src/Transaccional/Helpers/Builder/MailParams.php @@ -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'); } @@ -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, [