How do I send utf-8 characters in SMS messages through AWS SNS in PHP?

Viewed 410

I have the following simple code to send an SMS message according to an incoming api request, but the message arrives at the phone with the accents replaced by their corresponding ascii versions.

What should I change in order for a message like "You won the áéíóúñ product" to arrive properly?

<?php
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use Aws\Sns\SnsClient;
use Aws\Credentials\Credentials;

class Controller extends BaseController
{
  public function send(Request $request){    
    $to = $request->input('phone');
    $message = $request->input('message');

    $client = new SnsClient([
      'version' => '2010-03-31',
      'credentials' => new Credentials(
          env('SMS_AWS_ACCESS_KEY_ID'),
          env('SMS_AWS_SECRET_ACCESS_KEY')
      ),
      'region' => env('SMS_AWS_DEFAULT_REGION'),
    ]);

    $client->SetSMSAttributes([
      'attributes' => [
          'DefaultSMSType' => 'Transactional',
      ]
    ]);

    $client->publish([
      'Message' => $message,
      'PhoneNumber' => $to,
    ]);

    return [$to, $message];
  }
}

The package used to send the messages is the AWS SDK for PHP:
https://github.com/aws/aws-sdk-php

Official Documentation:
https://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.Sns.SnsClient.html

Some examples:
https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/sns-examples-sending-sms.html

This frustrated sad person has the only question I could find related to this issue:
https://forums.aws.amazon.com/thread.jspa?threadID=315153

0 Answers
Related