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

Precautions

  • 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 dysmsapi.ap-southeast-1.aliyuncs.com.
  • You must set the version parameter to 2018-05-01.

Sample code

<?php php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
// Download: https://github.com/aliyun/openapi-sdk-php-client
// Usage: https://github.com/aliyun/openapi-sdk-php-client/blob/master/README-CN.md
AlibabaCloud::accessKeyClient('<accessKeyId>', '<accessSecret>')
                        ->regionId('ap-southeast-1') 
                        ->asGlobalClient();
try {
    $result = AlibabaCloud::rpc()
                          ->product('Dysmsapi')
                          ->host('dysmsapi.ap-southeast-1.aliyuncs.com')
                          ->version('2014-11-11')
                          ->action('SendMessageToGlobe')
                          ->method('POST')
                          ->options([
                                        'query' => [
                                            "To" => "62123****8901",
                                            // "From" => "1234567890",
                                            "Message" => "have a test.",
                                        ],
                                    ])
                          ->request();
    print_r($result->toArray());
} catch (ClientException e) {
    echo $e->getErrorMessage() . PHP_EOL;
} catch (ServerException e) {
    echo $e->getErrorMessage() . PHP_EOL;
}