В реестре отечественного ПО

Примеры PHP запросов

Примеры PHP запросов

Получение списка групп получателей

  <?php
  $base_url = 'https://app.smsgold.ru/v1/email/';
  $token = 'TOKEN';
  $headers = array(
    'Authorization: Bearer ' . $token,
    'Content-Type: application/json'
  );
  $ch = curl_init($base_url . 'lists');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  $response = curl_exec($ch);
  curl_close($ch);
  echo $response . "\n";

Получение параметров для группы получателей

  <?php
  $base_url = 'https://app.smsgold.ru/v1/email/';
  $token = 'TOKEN';
  $headers = array(
    'Authorization: Bearer ' . $token,
    'Content-Type: application/json'
  );
  $list_id = 'LIST ID';
  $ch = curl_init($base_url . 'lists/' . $list_id . '/parameters');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  $response = curl_exec($ch);
  curl_close($ch);
  echo $response . "\n";

Добавление получателя в группу

  <?php
  $base_url = 'https://app.smsgold.ru/v1/email/';
  $token = 'TOKEN';
  $headers = array(
    'Authorization: Bearer ' . $token,
    'Content-Type: application/json'
  );
  $list_id = 'LIST ID';
  $parameter_id = 'PARAMETER ID';
  $data = array(
    'email'  => 'foo@bar.com',
    'values' => [
      array(
        'value' => 'Foo',
        'parameter_id' => $parameter_id
      )
    ]
  );
  $ch = curl_init($base_url . 'lists/' . $list_id . '/recipients');
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE));
  $response = curl_exec($ch);
  curl_close($ch);
  echo $response . "\n";

Импорт получателей в группу

  <?php
  $base_url = 'https://app.smsgold.ru/v1/email/';
  $token = 'TOKEN';
  $headers = array(
    'Authorization: Bearer ' . $token,
    'Content-Type: application/json'
  );
  $list_id = 'LIST ID';
  $parameter_id = 'PARAMETER_ID';
  $data = array(
    'recipients' => [
      array(
        'email'  => 'foo@bar.com',
        'values' => [
          array(
            'value' => 'Foo',
            'parameter_id' => $parameter_id
          )
        ]
      ),
      array(
        'email'  => 'bar@foo.com',
        'values' => [
          array(
            'value' => 'Bar',
            'parameter_id' => $parameter_id
          )
        ]
      )
    ]
  );
  $ch = curl_init($base_url . 'lists/' . $list_id . '/recipients/imports');
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE));
  $response = curl_exec($ch);
  curl_close($ch);
  echo $response . "\n";

Отправка одиночного сообщения

  <?php
  $base_url = 'https://app.smsgold.ru/v1/email/';
  $token = 'TOKEN';
  $headers = array(
    'Authorization: Bearer ' . $token,
    'Content-Type: application/json'
  );
  $from_email = 'SENDER';
  $to = 'RECIPIENT';
  $subject = 'Test';
  $text = 'Hello from API';
  $data = array(
    'from_email' => $from_email,
    'to' => $to,
    'subject' => $subject,
    'text' => $text
  );
  $ch = curl_init($base_url . 'messages');
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE));
  $response = curl_exec($ch);
  curl_close($ch);
  echo $response . "\n";

Отправка одиночного сообщения с вложениями

  <?php
  $base_url = 'https://app.smsgold.ru/v1/email/';
  $token = 'TOKEN';
  $headers = array(
    'Authorization: Bearer ' . $token,
  );
  $from_email = 'SENDER';
  $to = 'RECIPIENT';
  $subject = 'Test';
  $text = 'Hello from API';
  $data = array(
    'from_email' => $from_email,
    'to' => $to,
    'subject' => $subject,
    'text' => $text,
    'attachments[][0]' => curl_file_create('/path/to/file1'),
    'attachments[][1]' => curl_file_create('/path/to/file2')
  );
  $ch = curl_init($base_url . 'messages');
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  $response = curl_exec($ch);
  curl_close($ch);
  echo $response . "\n";

Отправка сообщения по SMTP

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$smtp_config = [
  'host' => 'smtp.msndr.net',
  'port' => 587,
  'username' => 'CHANGE_ME',
  'password' => 'CHANGE_ME',
  'from' => 'CHANGE_ME',
  'to' => 'CHANGE_ME',
  'subject' => 'Test Subject',
  'message' => 'Test Message'
];
extract($smtp_config);
$s = fsockopen($host, $port);
if ($s) {
  fgets($s);
  fputs($s, "EHLO localhost\r\n"); while(fgets($s)){}
    $auth = base64_encode("\0" . $username . "\0" . $password);
  fputs($s, "AUTH PLAIN $auth\r\n");
  if (strpos(fgets($s), '235') !== false) {
    fputs($s, "MAIL FROM: <$from>\r\n"); fgets($s);
    fputs($s, "RCPT TO: <$to>\r\n"); fgets($s);
    fputs($s, "DATA\r\n"); fgets($s);
    fputs($s, "Subject: $subject\r\n\r\n$message\r\n.\r\n");
    echo "Result: " . fgets($s);
  } else {
    echo "Authentication failed";
  }
  fputs($s, "QUIT\r\n");
  fclose($s);
} else {
  echo "Connection failed";
}

Мы используем cookies, чтобы сайт работал лучше. Подробнее.
Согласен