protected function _mapToSwift(SendGrid\Email $mail)
 {
     $message = new \Swift_Message($mail->getSubject());
     /*
      * Since we're sending transactional email, we want the message to go to one person at a time, rather
      * than a bulk send on one message. 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->to);
     $message->setFrom($mail->getFrom(true));
     $message->setCc($mail->getCcs());
     $message->setBcc($mail->getBccs());
     if ($mail->getHtml()) {
         $message->setBody($mail->getHtml(), 'text/html');
         if ($mail->getText()) {
             $message->addPart($mail->getText(), 'text/plain');
         }
     } else {
         $message->setBody($mail->getText(), 'text/plain');
     }
     if ($replyto = $mail->getReplyTo()) {
         $message->setReplyTo($replyto);
     }
     $attachments = $mail->getAttachments();
     //add any attachments that were added
     if ($attachments) {
         foreach ($attachments as $attachment) {
             $message->attach(\Swift_Attachment::fromPath($attachment['file']));
         }
     }
     $message_headers = $message->getHeaders();
     $message_headers->addTextHeader("x-smtpapi", $mail->smtpapi->jsonString());
     return $message;
 }
Esempio n. 2
0
 public function testAddCc()
 {
     $email = new \SendGrid\Email();
     $email->addCc('*****@*****.**');
     $email->addCc('*****@*****.**');
     $this->assertEquals(2, count($email->getCcs()));
     $cc = $email->getCcs();
     $this->assertEquals('*****@*****.**', $cc[0]);
     $this->assertEquals('*****@*****.**', $cc[1]);
     // removeCc removes all occurences of data
     $email->removeCc('*****@*****.**');
     $this->assertEquals(1, count($email->getCcs()));
     $cc = $email->getCcs();
     $this->assertEquals('*****@*****.**', $cc[0]);
 }
 public function testAddCc()
 {
     $email = new SendGrid\Email();
     $email->addCc('foo');
     $email->addCc('raz');
     $this->assertEquals(2, count($email->getCcs()));
     $cc_list = $email->getCcs();
     $this->assertEquals('foo', $cc_list[0]);
     $this->assertEquals('raz', $cc_list[1]);
     // removeTo removes all occurences of data
     $email->removeCc('raz');
     $this->assertEquals(1, count($email->getCcs()));
     $cc_list = $email->getCcs();
     $this->assertEquals('foo', $cc_list[0]);
 }