Question

I'm using AWS SDK for PHP (https://github.com/aws/aws-sdk-php) to send emails using Amazon SES. Here's the code:

<?php

require 'vendor/autoload.php';

use Aws\Ses\SesClient;

$client = SesClient::factory(array(
    'key'    => 'XXXXXXXXXXXXXXXX',
    'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
    'region' => 'eu-west-1'
));

$result = $client->sendEmail(array(
    // Source is required
    'Source' => 'Télécom Co <email@address.com>',
    // Destination is required
    'Destination' => array(
        'ToAddresses' => array('Grégory Smith <another_email@address.com>')
    ),
    // Message is required
    'Message' => array(
        // Subject is required
        'Subject' => array(
            // Data is required
            'Data' => 'The subject',
            'Charset' => 'utf-8',
        ),
        // Body is required
        'Body' => array(
            'Text' => array(
                // Data is required
                'Data' => 'The message',
                'Charset' => 'utf-8',
            )
        ),
    )
));

?>

The problem is that in the email clients "Télécom" appears like "T�l�com" and "Grégory" like "Gr�gory".

Are there any solutions for this problem ?

Was it helpful?

Solution

Here's the solution:

<?php

require 'vendor/autoload.php';

use Aws\Ses\SesClient;

$client = SesClient::factory(array(
    'key'    => 'XXXXXXXXXXXXXXXX',
    'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
    'region' => 'eu-west-1'
));


$from_name = base64_encode("Télécom Co");
$from = "=?utf-8?B?$from_name?= <email@address.com>";

$to_name = base64_encode('Grégory Smith');
$to = array("=?utf-8?B?$to_name?= <another_email@address.com>");


$result = $client->sendEmail(array(
    // Source is required
    'Source' => $from,
    // Destination is required
    'Destination' => array(
        'ToAddresses' => $to
    ),
    // Message is required
    'Message' => array(
        // Subject is required
        'Subject' => array(
            // Data is required
            'Data' => 'The subject',
            'Charset' => 'utf-8',
        ),
        // Body is required
        'Body' => array(
            'Text' => array(
                // Data is required
                'Data' => 'The message',
                'Charset' => 'utf-8',
            )
        ),
    )
));

?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top