Amazon SES 中的特殊字符
Posted
技术标签:
【中文标题】Amazon SES 中的特殊字符【英文标题】:Special Characters in Amazon SES 【发布时间】:2014-03-19 12:40:09 【问题描述】:我正在使用 AWS SDK for php (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”。
这个问题有解决办法吗?
【问题讨论】:
【参考方案1】:解决办法如下:
<?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',
)
),
)
));
?>
【讨论】:
是的,RFC 2047 要求对非 ASCII 邮件标头进行编码。以上是关于Amazon SES 中的特殊字符的主要内容,如果未能解决你的问题,请参考以下文章