# Using Twilio PHP SDK

If you are using the Twilio PHP SDK, you can swap out the URL to point to the MessageBird Twilio Adapter, by using a custom HTTP Client.

```php
<?php

class MyTwilioAdapterClient extends Twilio\Http\CurlClient
{

    public function options(
        string $method,
        string $url,
        array $params = [],
        array $data = [],
        array $headers = [],
        string $user = null,
        string $password = null,
        int $timeout = null
    ): array {
        $adapterUrl = str_replace("https://api.twilio.com/", "https://eu-west-1.twilio.to.nest.messagebird.com/", $url);

        return parent::options($method, $adapterUrl, $params, $data, $headers, $user, $password, $timeout);
    }
}

// Your Account SID and Auth Token
$accountSid = "ACXXXXXX";
$authToken = "YYYYYY";

$httpClient = new MyTwilioAdapterClient();
$client = new Twilio\Rest\Client($accountSid, $authToken, null, null, $httpClient);
```

You can try it out with the following example:

```php
<?php

// Required if your environment does not handle autoloading
require __DIR__ . '/vendor/autoload.php';

class MyTwilioAdapterClient extends Twilio\Http\CurlClient
{
    public function options(
        string $method,
        string $url,
        array $params = [],
        array $data = [],
        array $headers = [],
        string $user = null,
        string $password = null,
        int $timeout = null
    ): array {
        $adapterUrl = str_replace("https://api.twilio.com/", "https://eu-west-1.twilio.to.nest.messagebird.com/", $url);

        return parent::options($method, $adapterUrl, $params, $data, $headers, $user, $password, $timeout);
    }
}

// Your Account SID and Auth Token
$accountSid = "ACXXXXXX";
$authToken = "YYYYYY";

$httpClient = new MyTwilioAdapterClient();
$client = new Twilio\Rest\Client($accountSid, $authToken, null, null, $httpClient);

// Use the Client to make requests to the MessageBird Twilio Adapter
$client->messages->create(
    // The number you'd like to send the message to
    '+15558675309',
    [
        // A valid MessageBird phone number
        'from' => '+15017250604',
        // The body of the text message you'd like to send
        'body' => "Hey Jenny! Good luck on the bar exam!"
    ]
);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bird.com/api/channels-api/supported-channels/programmable-sms/twilio-exit-api/using-twilio-php-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
