Permalink
Browse files

Fixed the smtp library to send the recipients through the headers rat…

…her than the the normal 'to' field, so that the recipients will get different messages, rather than sharing the same one.
  • Loading branch information...
1 parent 0a5e73a commit fa6367a2b6fd687120741f97c3a5edeaa0ecf723 CJ Buchmann committed Feb 13, 2012
Showing with 13 additions and 15 deletions.
  1. +13 −15 SendGrid/Smtp.php
View
@@ -62,23 +62,16 @@ private function _getSwiftInstance($port)
protected function _mapToSwift(Mail $mail)
{
$message = new \Swift_Message($mail->getSubject());
-
- $recipients = array();
- foreach($mail->getTos() as $recipient)
- {
- if(preg_match("/(.*)<(.*)>/", $recipient, $results))
- {
- $recipients[trim($results[2])] = trim($results[1]);
- }
- else
- {
- $recipients[] = $recipient;
- }
- }
-
+
+ /*
+ * Since we're sending transactional email, we want the message to go to one person at a time, rather
+ * than a bulk send. In order to do this, we'll have to send the list of recipients through the headers
+ * but Swift still requires a 'to' address. So we'll falsify it with the from address, as it will be
+ * ignored anyway.
+ */
+ $message->setTo($mail->getFrom());
$message->setFrom($mail->getFrom());
$message->setBody($mail->getHtml(), 'text/html');
- $message->setTo($recipients);
$message->addPart($mail->getText(), 'text/plain');
$message->setCc($mail->getCcs());
$message->setBcc($mail->getBccs());
@@ -94,6 +87,11 @@ protected function _mapToSwift(Mail $mail)
}
}
+ //here we'll add the recipients list to the headers
+ $headers = $mail->getHeaders();
+ $headers['to'] = $mail->getTos();
+ $mail->setHeaders($headers);
+
//add all the headers
$headers = $message->getHeaders();
$headers->addTextHeader('X-SMTPAPI', $mail->getHeadersJson());

0 comments on commit fa6367a

Please sign in to comment.