Example #1
0
 public function testUserData()
 {
     $message = new Message();
     // To
     $message->setTo(['*****@*****.**' => ['name' => 'Recipient #1', 'metadata' => ['key' => 'value'], 'substitution_data' => ['template_key' => 'value'], 'tags' => ['tag1', 'tag2']]]);
     $this->assertEquals(['*****@*****.**' => 'Recipient #1'], $message->getTo());
     $this->assertEquals(['*****@*****.**' => ['metadata' => ['key' => 'value'], 'substitution_data' => ['template_key' => 'value'], 'tags' => ['tag1', 'tag2']]], $message->getUserData());
     // Sparkpost array
     $this->assertEquals([['address' => ['email' => '*****@*****.**', 'name' => 'Recipient #1'], 'metadata' => ['key' => 'value'], 'substitution_data' => ['template_key' => 'value'], 'tags' => ['tag1', 'tag2']]], $message->toSparkPostArray()['recipients']);
     // Cc
     $message->setCc(['*****@*****.**' => ['name' => 'Recipient #1', 'metadata' => ['key' => 'value'], 'substitution_data' => ['template_key' => 'value'], 'tags' => ['tag1', 'tag2']]]);
     $this->assertEquals(['*****@*****.**' => 'Recipient #1'], $message->getCc());
     $this->assertEquals(['*****@*****.**' => ['metadata' => ['key' => 'value'], 'substitution_data' => ['template_key' => 'value'], 'tags' => ['tag1', 'tag2']]], $message->getUserData());
     // Bcc
     $message->setBcc(['*****@*****.**' => ['name' => 'Recipient #1', 'metadata' => ['key' => 'value'], 'substitution_data' => ['template_key' => 'value'], 'tags' => ['tag1', 'tag2']]]);
     $this->assertEquals(['*****@*****.**' => 'Recipient #1'], $message->getBcc());
     $this->assertEquals(['*****@*****.**' => ['metadata' => ['key' => 'value'], 'substitution_data' => ['template_key' => 'value'], 'tags' => ['tag1', 'tag2']]], $message->getUserData());
 }
Example #2
0
 /**
  * @param Message $message
  * @return bool
  */
 protected function internalSend($message)
 {
     $result = $this->_sparkPost->transmission->send($message->toSparkPostArray());
     $this->lastTransmissionId = ArrayHelper::getValue($result, 'results.id');
     // Rejected messages.
     $this->rejectedCount = ArrayHelper::getValue($result, 'results.total_rejected_recipients');
     if ($this->rejectedCount > 0) {
         \Yii::info("Transmission #{$this->lastTransmissionId}: {$this->rejectedCount} rejected", self::LOG_CATEGORY);
     }
     // Sent messages.
     $this->sentCount = ArrayHelper::getValue($result, 'results.total_accepted_recipients');
     if ($this->sentCount === 0) {
         \Yii::info("Transmission #{$this->lastTransmissionId} was rejected: all {$this->rejectedCount} rejected", self::LOG_CATEGORY);
         return false;
     }
     return true;
 }