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()); }
/** * Refer to the error codes descriptions to see details. * * @link https://support.sparkpost.com/customer/en/portal/articles/2140916-extended-error-codes Errors descriptions * @param Message $message * @return bool * @throws APIResponseException */ protected function sendMessage($message) { // Clear info about last transmission. $this->lastTransmissionId = $this->lastError = null; $this->sentCount = $this->rejectedCount = 0; if (!$message->getTo()) { \Yii::warning('Message was not sent, because "to" recipients list is empty', self::LOG_CATEGORY); return false; } $attemptsCount = 0; while ($attemptsCount <= $this->retryLimit) { $attemptsCount++; try { return $this->internalSend($message); } catch (APIResponseException $e) { $this->lastError = $e; } } // Transmission wasn't sent. \Yii::error("An error occurred in mailer: {$this->lastError->getMessage()}, code: {$this->lastError->getAPICode()}, api message: \"{$this->lastError->getAPIMessage()}\", api description: \"{$this->lastError->getAPIDescription()}\"", self::LOG_CATEGORY); if ($this->developmentMode) { throw $this->lastError; } else { return false; } }