php - Amazon SES 中的特殊字符

标签 php amazon amazon-ses

我正在使用适用于 PHP 的 AWS 开发工具包 (https://github.com/aws/aws-sdk-php) 通过 Amazon SES 发送电子邮件。 这是代码:

<?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',
            )
        ),
    )
));

?>

问题是在电子邮件客户端中,“Télécom”显示为“T�l�com”,而“Grégory”显示为“Gr�gory”。

这个问题有什么解决方案吗?

最佳答案

解决方法如下:

<?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',
            )
        ),
    )
));

?>

关于php - Amazon SES 中的特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21876157/

相关文章:

php - 使用外键填充表

php - 无法从 sql 结果通知中输出字符串变量

PHP ffmpeg 将 GIF 转换为 MP4

android - WebView 中的 Kindle Fire 和 Youtube 链接

amazon-web-services - 如何使用我的用户(未经验证)地址作为 Amazon SES 的发件人?

php - codeigniter 空格或标题导致警告

amazon - 使用 Uploadify 直接发布到 Amazon S3

node.js - 亚马逊 ELB 后面带有 node-js 的远程 IP 地址

javascript - node.js 上的 SES 尽管返回 'success' 响应但未发送电子邮件

amazon-web-services - 亚马逊SES异常: IAM User is not authorized to perform `ses:SendRawEmail' on resource