Skip to content

Commit

Permalink
Changes to send to multiple emails without displaying all of them in …
Browse files Browse the repository at this point in the history
…the to field
  • Loading branch information
pochocho committed Apr 20, 2016
1 parent 934c915 commit 3d9e502
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/Illuminate/Mail/Transport/SparkPostTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)
$this->beforeSendPerformed($message);

$recipients = $this->getRecipients($message);

//dd($recipients);
$message->setBcc([]);

$options = [
Expand All @@ -52,7 +52,9 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)
'json' => [
'recipients' => $recipients,
'content' => [
'email_rfc822' => $message->toString(),
'html' => $message->getBody(),
'from' => $this->getFrom($message),
'subject' => $message->getSubject()
],
],
];
Expand All @@ -70,7 +72,7 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)
*/
protected function getRecipients(Swift_Mime_Message $message)
{
$to = [];
$to = $bcc = [];

if ($message->getTo()) {
$to = array_merge($to, array_keys($message->getTo()));
Expand All @@ -81,14 +83,34 @@ protected function getRecipients(Swift_Mime_Message $message)
}

if ($message->getBcc()) {
$to = array_merge($to, array_keys($message->getBcc()));
$bcc = array_merge($bcc, array_keys($message->getBcc()));
$recipients_bcc = array_map(function ($address) {
return ['address' => [ 'email' => $address ,'header_to' => $address] ];
}, $bcc);
}

$recipients = array_map(function ($address) {
return compact('address');
$recipients_to = array_map(function ($address) {
return ['address' => [ 'email' => $address] ];
// return compact('address');
}, $to);

return $recipients;
return (isset($recipients_bcc)) ? $recipients_to + $recipients_bcc : $recipients_to;
}

/**
* Get From in a format needed by SparkPost
*
* @param Swift_Mime_Message $message
* @return array
*/
protected function getFrom(Swift_Mime_Message $message)
{

$from = array_map(function ($email, $name) {
return [ 'name' => $name, 'email' => $email ];
}, array_keys($message->getFrom()), $message->getFrom() );

return $from[0];
}

/**
Expand Down

0 comments on commit 3d9e502

Please sign in to comment.