Skip to content

Commit

Permalink
Merge pull request #32 from hlev/remove-to-requirement
Browse files Browse the repository at this point in the history
Docblocks fixed; Updated validation for recipients lists
  • Loading branch information
daniel-zahariev authored Apr 12, 2017
2 parents 48ecc84 + 7270943 commit e82ef20
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 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
4 changes: 2 additions & 2 deletions src/SimpleEmailServiceRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class SimpleEmailServiceRequest
/**
* Constructor
*
* @param string $ses The SimpleEmailService object making this request
* @param SimpleEmailService $ses The SimpleEmailService object making this request
* @param string $verb HTTP verb
* @return void
*/
Expand Down Expand Up @@ -244,7 +244,7 @@ private function __customUrlEncode($var) {
/**
* Generate the auth string using Hmac-SHA256
*
* @internal Used by SimpleDBRequest::getResponse()
* @internal Used by SimpleEmailServiceRequest::getResponse()
* @param string $string String to sign
* @return string
*/
Expand Down

0 comments on commit e82ef20

Please sign in to comment.