getFrom example


        return $message instanceof SmsMessage && (null === $message->getOptions() || $message->getOptions() instanceof EsendexOptions);
    }

    protected function doSend(MessageInterface $message): SentMessage
    {
        if (!$message instanceof SmsMessage) {
            throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class$message);
        }

        $options = $message->getOptions()?->toArray() ?? [];
        $options['from'] = $message->getFrom() ?: $this->from;
        $options['messages'] = [
            [
                'to' => $message->getPhone(),
                'body' => $message->getSubject(),
            ],
        ];
        $options['accountreference'] ??= $this->accountReference;

        $response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/v1.0/messagedispatcher', [
            'auth_basic' => [$this->email, $this->password],
            'headers' => [
                
return $message instanceof SmsMessage;
    }

    protected function doSend(MessageInterface $message): SentMessage
    {
        if (!$message instanceof SmsMessage) {
            throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class$message);
        }

        $response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/v3/transactionalSMS/sms', [
            'json' => [
                'sender' => $message->getFrom() ?: $this->sender,
                'recipient' => $message->getPhone(),
                'content' => $message->getSubject(),
            ],
            'headers' => [
                'api-key' => $this->apiKey,
            ],
        ]);

        try {
            $statusCode = $response->getStatusCode();
        } catch (TransportExceptionInterface $e) {
            
$this->assertSame($fabien$e->getSender());
    }

    public function testFrom()
    {
        $e = new Email();
        $helene = new Address('helene@symfony.com');
        $thomas = new Address('thomas@symfony.com', 'Thomas');
        $caramel = new Address('caramel@symfony.com');

        $this->assertSame($e$e->from('fabien@symfony.com', $helene$thomas));
        $v = $e->getFrom();
        $this->assertCount(3, $v);
        $this->assertEquals(new Address('fabien@symfony.com')$v[0]);
        $this->assertSame($helene$v[1]);
        $this->assertSame($thomas$v[2]);

        $this->assertSame($e$e->addFrom('lucas@symfony.com', $caramel));
        $v = $e->getFrom();
        $this->assertCount(5, $v);
        $this->assertEquals(new Address('fabien@symfony.com')$v[0]);
        $this->assertSame($helene$v[1]);
        $this->assertSame($thomas$v[2]);
        
throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class$message);
        }

        $endpoint = sprintf('http://%s/api', $this->getEndpoint());
        $response = $this->client->request('POST', $endpoint[
            'query' => [
                'action' => 'sendmessage',
                'username' => $this->username,
                'password' => $this->password,
                'recipient' => $message->getPhone(),
                'messagetype' => 'SMS:TEXT',
                'originator' => $message->getFrom() ?: $this->sender,
                'messagedata' => $message->getSubject(),
            ],
        ]);

        try {
            $statusCode = $response->getStatusCode();
        } catch (TransportExceptionInterface $e) {
            throw new TransportException('Could not reach the remote KazInfoTeh server.', $response, 0, $e);
        }

        try {
            
public function supports(MessageInterface $message): bool
    {
        return $message instanceof SmsMessage;
    }

    protected function doSend(MessageInterface $message): SentMessage
    {
        if (!$message instanceof SmsMessage) {
            throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class$message);
        }

        $from = $message->getFrom() ?: $this->from;

        if (!preg_match('/^[+]+[1-9][0-9]{9,14}$/', $from)) {
            if ('' === $from) {
                throw new IncompleteDsnException('This phone number is invalid.');
            }

            if (!preg_match('/^[a-zA-Z0-9 ]+$/', $from)) {
                throw new IncompleteDsnException('The Sender ID is invalid.');
            }
        }

        

        $this->message->addFrom(new Address($address$name));

        return $this;
    }

    /** * @return Address[] */
    public function getFrom(): array
    {
        return $this->message->getFrom();
    }

    /** * @return $this */
    public function addReplyTo(string $address)static
    {
        $this->message->addReplyTo($address);

        return $this;
    }

    

        return $message instanceof SmsMessage && (null === $message->getOptions() || $message->getOptions() instanceof MessageMediaOptions);
    }

    protected function doSend(MessageInterface $message): SentMessage
    {
        if (!$message instanceof SmsMessage) {
            throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class$message);
        }

        $options = $message->getOptions()?->toArray() ?? [];
        $options['source_number'] = $message->getFrom() ?: $this->from;
        $options['destination_number'] = $message->getPhone();
        $options['content'] = $message->getSubject();

        $endpoint = sprintf('https://%s/v1/messages', $this->getEndpoint());
        $response = $this->client->request('POST', $endpoint[
            'auth_basic' => [$this->apiKey, $this->apiSecret],
            'json' => [
                'messages' => [
                    array_filter($options),
                ],
            ],
        ]);
return $message instanceof SmsMessage;
    }

    protected function doSend(MessageInterface $message): SentMessage
    {
        if (!$message instanceof SmsMessage) {
            throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class$message);
        }

        $response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/sms/json', [
            'body' => [
                'from' => $message->getFrom() ?: $this->from,
                'to' => $message->getPhone(),
                'text' => $message->getSubject(),
                'api_key' => $this->apiKey,
                'api_secret' => $this->apiSecret,
            ],
        ]);

        try {
            $result = $response->toArray(false);
        } catch (TransportExceptionInterface $e) {
            throw new TransportException('Could not reach the remote Vonage server.', $response, 0, $e);
        }
protected function doSend(MessageInterface $message): SentMessage
    {
        if (!$message instanceof SmsMessage) {
            throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class$message);
        }

        $messageId = bin2hex(random_bytes(7));
        $query = [
            'to' => $message->getPhone(),
            'text' => $message->getSubject(),
            'gsmsmsid' => $messageId,
            'sender' => $message->getFrom() ?: $this->sender,
            'pushtype' => $this->pushType?->value,
        ];

        $response = $this->client->request('GET', 'https://'.$this->getEndpoint().'/send', [
            'query' => array_filter($query),
            'auth_bearer' => $this->tokenApi,
            'headers' => [
                'Accept' => 'application/json',
            ],
        ]);

        
public function supports(MessageInterface $message): bool
    {
        return $message instanceof SmsMessage;
    }

    protected function doSend(MessageInterface $message): SentMessage
    {
        if (!$message instanceof SmsMessage) {
            throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class$message);
        }

        $sender = $message->getFrom() ?: $this->sender;

        $response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/v3/transactionalSMS/sms', [
            'json' => [
                'sender' => $sender,
                'recipient' => $message->getPhone(),
                'content' => $message->getSubject(),
            ],
            'headers' => [
                'api-key' => $this->apiKey,
            ],
        ]);

        
// default request body         $body = [
            'to' => $message->getPhone(),
            'message' => $message->getSubject(),
            'fast' => $this->fast,
            'format' => 'json',
            'encoding' => 'utf-8',
            'test' => $this->test,
        ];

        if ('' !== $from = $message->getFrom() ?: $this->from) {
            $body['from'] = $from;
        }

        $endpoint = sprintf('https://%s/sms.do', $this->getEndpoint());
        $response = $this->client->request('POST', $endpoint[
            'auth_bearer' => $this->authToken,
            'body' => $body,
        ]);

        try {
            $statusCode = $response->getStatusCode();
        }


        $endpoint = sprintf('https://%s/sms/2/text/advanced', $this->getEndpoint());

        $response = $this->client->request('POST', $endpoint[
            'headers' => [
                'Authorization' => 'App '.$this->authToken,
            ],
            'json' => [
                'messages' => [
                    [
                        'from' => $message->getFrom() ?: $this->from,
                        'destinations' => [
                            [
                                'to' => $message->getPhone(),
                            ],
                        ],
                        'text' => $message->getSubject(),
                    ],
                ],
            ],
        ]);

        
$rule->setPrice($price);

            $rule->setPseudoPrice($pseudo);

            $rule->setFrom($discount->getQuantity());

            $rule->setCustomerGroup($customerGroup);

            $rule->setTo(null);
            if ($previous) {
                $previous->setTo($rule->getFrom() - 1);
            }

            $previous = $rule;
            $prices[] = $rule;
        }

        return $prices;
    }

    /** * Helper function which iterates the products and builds a price array which indexed * with the product order number. * * @param ListProduct[] $products * @param array<string, array<PriceRule>> $priceRules * * @return array<string, array<PriceRule>> */

        return $message instanceof SmsMessage;
    }

    protected function doSend(MessageInterface $message): SentMessage
    {
        if (!$message instanceof SmsMessage) {
            throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class$message);
        }

        $options = [];
        $options['from'] = $message->getFrom() ?: $this->from;
        $options['to'] = $message->getPhone();
        $options['message'] = $message->getSubject();

        $endpoint = sprintf('https://%s/a1/sms', $this->getEndpoint());
        $response = $this->client->request('POST', $endpoint[
            'auth_basic' => [$this->apiUsername, $this->apiPassword],
            'body' => array_filter($options),
        ]);

        try {
            $statusCode = $response->getStatusCode();
        }
$mailer = new DummyMailer();

        $transport = (new FakeChatEmailTransport($mailer$to = 'recipient@email.net', $from = 'sender@email.net'));
        $transport->setHost($transportName);

        $transport->send($message);

        /** @var Email $sentEmail */
        $sentEmail = $mailer->getSentEmail();
        $this->assertInstanceOf(Email::class$sentEmail);
        $this->assertSame($to$sentEmail->getTo()[0]->getEncodedAddress());
        $this->assertSame($from$sentEmail->getFrom()[0]->getEncodedAddress());
        $this->assertSame(sprintf('New Chat message for recipient: %s', $recipient)$sentEmail->getSubject());
        $this->assertSame($subject$sentEmail->getTextBody());
        $this->assertFalse($sentEmail->getHeaders()->has('X-Transport'));
    }

    public function testSendWithDefaultTransportAndWithoutRecipient()
    {
        $transportName = null;

        $message = new ChatMessage($subject = 'Hello!');

        
Home | Imprint | This part of the site doesn't use cookies.