Skip to content

Commit

Permalink
change validation, omit To header from raw message if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
lhuszko committed Jul 9, 2016
1 parent b991c02 commit 7270943
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/SimpleEmailServiceMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -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)
{
Expand All @@ -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.
*
Expand All @@ -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)
Expand Down

0 comments on commit 7270943

Please sign in to comment.