From 72709439a54f05ffe8df72fbf0f8299a92d62d67 Mon Sep 17 00:00:00 2001 From: Levente Huszko Date: Sat, 9 Jul 2016 06:42:37 -0400 Subject: [PATCH] change validation, omit To header from raw message if empty --- src/SimpleEmailServiceMessage.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/SimpleEmailServiceMessage.php b/src/SimpleEmailServiceMessage.php index 6eb23b6..17bfe8f 100644 --- a/src/SimpleEmailServiceMessage.php +++ b/src/SimpleEmailServiceMessage.php @@ -266,7 +266,7 @@ public function addAttachmentFromData($name, $data, $mimeType = 'application/oct * @param string $mimeType Specify custom MIME type * @param string $contentId Content ID of the attachment for inclusion in the mail message * @param string $attachmentType Attachment type: attachment or inline - * @return boolean Status of the operation + * @return boolean Status of the operation */ public function addAttachmentFromFile($name, $path, $mimeType = 'application/octet-stream', $contentId = null, $attachmentType = 'attachment') { if (file_exists($path) && is_file($path) && is_readable($path)) { @@ -284,7 +284,7 @@ public function addAttachmentFromFile($name, $path, $mimeType = 'application/oct * @param string $mimeType Specify custom MIME type * @param string $contentId Content ID of the attachment for inclusion in the mail message * @param string $attachmentType Attachment type: attachment or inline - * @return boolean Status of the operation + * @return boolean Status of the operation */ public function addAttachmentFromUrl($name, $url, $mimeType = 'application/octet-stream', $contentId = null, $attachmentType = 'attachment') { $data = file_get_contents($url); @@ -318,8 +318,8 @@ public function hasInlineAttachments() public function getRawMessage() { $boundary = uniqid(rand(), true); - $raw_message = (count($this->customHeaders) > 0 ? join("\n", $this->customHeaders) . "\n" : ''); - $raw_message .= 'To:' . $this->encodeRecipients($this->to) . "\n"; + $raw_message = count($this->customHeaders) > 0 ? join("\n", $this->customHeaders) . "\n" : ''; + $raw_message .= count($this->to) > 0 ? 'To:' . $this->encodeRecipients($this->to) . "\n" : ''; $raw_message .= 'From:' . $this->encodeRecipients($this->from) . "\n"; if(!empty($this->replyto)) $raw_message .= 'Reply-To:' . $this->encodeRecipients($this->replyto) . "\n"; @@ -373,7 +373,7 @@ public function getRawMessage() /** * Encode recipient with the specified charset in `recipientsCharset` * - * @return string Encoded recipients joined with comma + * @return string Encoded recipients joined with comma */ public function encodeRecipients($recipient) { @@ -390,6 +390,7 @@ public function encodeRecipients($recipient) /** * Validates whether the message object has sufficient information to submit a request to SES. + * * This does not guarantee the message will arrive, nor that the request will succeed; * instead, it makes sure that no required fields are missing. * @@ -401,16 +402,16 @@ public function encodeRecipients($recipient) * @return boolean */ public function validate() { - // at least one To: destination is required - if(count($this->to) == 0) + // at least one destination is required + if (count($this->to) == 0 && count($this->cc) == 0 && count($this->bcc) == 0) return false; // sender is required - if($this->from == null || strlen($this->from) == 0) + if ($this->from == null || strlen($this->from) == 0) return false; // subject is required - if(($this->subject == null || strlen($this->subject) == 0)) return false; + if (($this->subject == null || strlen($this->subject) == 0)) return false; // message is required if ((empty($this->messagetext) || strlen((string)$this->messagetext) == 0)