aws / aws-sdk-php

Official repository of the AWS SDK for PHP (@awsforphp)
http://aws.amazon.com/sdkforphp
Apache License 2.0
6k stars 1.22k forks source link

Special Chars problem #238

Closed rzds closed 10 years ago

rzds commented 10 years ago

When sending an email to a destination like this "Grégory Smith < someaddress@gmail.com >" the é is displayed incorrect. See the screenshot chars

jeremeamia commented 10 years ago

How are you sending it?

skyzyx commented 10 years ago

You need to encode the non-ASCII header value.


http://docs.aws.amazon.com/ses/latest/APIReference/API_SendEmail.html

By default, the string must be 7-bit ASCII. If the text must contain any other characters, then you must use MIME encoded-word syntax (RFC 2047) instead of a literal string. MIME encoded-word syntax uses the following form: =?charset?encoding?encoded-text?=. For more information, see RFC 2047.

https://en.wikipedia.org/wiki/MIME

Since RFC 2822, conforming message header names and values should be ASCII characters; values that contain non-ASCII data should use the MIME encoded-word syntax (RFC 2047) instead of a literal string. This syntax uses a string of ASCII characters indicating both the original character encoding (the "charset") and the content-transfer-encoding used to map the bytes of the charset into ASCII characters.

http://tools.ietf.org/html/rfc2047

An 'encoded-word' may replace a 'text' token (as defined by RFC 822) in any Subject or Comments header field, any extension message header field, or any MIME body part field for which the field body is defined as '*text'. An 'encoded-word' may also appear in any user-defined ("X-") message or body part header field.


@jeremeamia: This might be a good use-case for a utility class to be added to the SDK.

rzds commented 10 years ago

It's a shame this huuuuge SDK doesn't already do the encoding of the source and destinations.

I end up doing something like this:

<?php

require 'vendor/autoload.php';

use Aws\Ses\SesClient;

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

$encoded_name = base64_encode("Grégory Smith");
$address = "=?utf-8?B?$encoded_name?= <some@address.com>";

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

?>
skyzyx commented 10 years ago

Use Composer on deployment, and a few hundred kilobytes is really not a big deal.

But yes, I agree that support for this should be added to the SDK. Thanks for making the team aware of this need.

jeremeamia commented 10 years ago

Cool, I'm glad you got it working. Thanks for helping out @skyzyx. I've put it into our internal backlog to consider adding something to help with this.