Exemplo n.º 1
0
 /**
  * @param \Nette\Mail\Message $message
  * @param callable $setup
  * @return void
  */
 public function send(\Nette\Mail\Message $message, $setup = NULL)
 {
     $message = $this->converter->convert($message);
     if ($setup) {
         $setup($message);
     }
     $this->mailer->send($message);
 }
Exemplo n.º 2
0
 /**
  * Sends a SMS on the Clickatell API.
  *
  * @param string $number  The phone number, in international format, without the leading +.
  * @param string $message The text message, in UTF-8 format.
  * @param array  $options Additional options: from, callback, concat, ...
  *
  * @return string The message ID.
  *
  * @throws \Clickatell\ClickatellException
  */
 public function send($number, $message, array $options = [])
 {
     if (!ctype_digit($number)) {
         throw new ClickatellException('Invalid phone number.');
     }
     $message = $this->messageConverter->convert($message);
     $parameters = ['api_id' => $this->apiId, 'user' => $this->username, 'password' => $this->password, 'to' => $number, 'unicode' => $message->isUnicode ? '1' : '0', 'text' => $message->data];
     $parameters += $options;
     $response = $this->post(self::SENDMSG_ENDPOINT, $parameters);
     if (preg_match('/^ID: (\\S+)/', $response, $matches) == 0) {
         if (preg_match('/^ERR: ([0-9]+), (.+)/', $response, $matches) == 0) {
             throw new ClickatellException('Invalid sendmsg response: ' . $response);
         }
         throw new ClickatellException($matches[2], $matches[1]);
     }
     return $matches[1];
 }