All Products
Document Center

Short Message Service:Sample PHP code

Last Updated:Oct 10, 2022

This topic describes how to use the PHP SDK to call the SendMessageToGlobe operation to send SMS messages to regions outside the Chinese mainland.


  • You must set the regionId parameter to ap-southeast-1.

  • You must set the product parameter to Dysmsapi.

  • You must set the host parameter to

  • You must set the version parameter to 2018-05-01.

Sample code

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
// Download:
// Usage:
AlibabaCloud::accessKeyClient('<accessKeyId>', '<accessSecret>')
try {
    $result = AlibabaCloud::rpcRequest()
                                        'query' => [
                                            "To" => "62123****8901",
                                            // "From" => "1234567890",
                                            "Message" => "have a test.",
} catch (ClientException $e) {
    echo $e->getErrorMessage() . PHP_EOL;
} catch (ServerException $e) {
    echo $e->getErrorMessage() . PHP_EOL;