Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $userId = "ba514d06f57002bdd86362cfa0784852";
- $secret = "dc7c780390f87f51a1c201e2cfdcca0a";
- $addressBookName = "Новый список 1";
- $email = $this->getParameters()->getData("contact_email");
- $phone = $this->getParameters()->getData("contact_phone");
- $sendPulse = new \SendpulseApi($userId, $secret, new \FileStorage());
- $addressBooks = $sendPulse->listAddressBooks();
- /** @var \stdClass $foundAddressBook */
- $foundAddressBook = null;
- foreach ($addressBooks as $addressBook) {
- if ($addressBook->name == $addressBookName) {
- $foundAddressBook = $addressBook;
- break;
- }
- }
- if (is_null($foundAddressBook)) {
- return;
- }
- $data = new \stdClass();
- $data->email = $email;
- $data->phone = $phone;
- $result = $sendPulse->addEmails($foundAddressBook->id, [
- "email" => $email,
- "phone" => $phone,
- ]);
- /**
- // Этот вариант выдавал ошибку HTTP код ответа 500
- $result = $sendPulse->addEmails($foundAddressBook->id, [
- "email" => $email,
- "variables" => [
- "phone" => $phone
- ]
- ]);
- */
- if (isset($result->is_error) && $result->is_error) {
- Log::get()->put(
- "Send Pulse error: " .
- $result->http_code . " " . $result->message . " " .
- $result->error_code,
- Log::LEVEL_ERROR
- );
- return false;
- }
- if(isset($result->result) && $result->result) {
- Log::get()->put(
- "Send Pulse success",
- Log::LEVEL_INFO
- );
- return true;
- }
- return false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement