2014-02-19 151 views
5

我正在使用適用於PHP的AWS SDK(https://github.com/aws/aws-sdk-php)使用Amazon SES發送電子郵件。 下面的代碼:亞馬遜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 protected]>', 
    // Destination is required 
    'Destination' => array(
     'ToAddresses' => array('Grégory Smith <[email protected]>') 
    ), 
    // 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」和「高利」的,如「Gr�gory」。

有沒有解決這個問題的方法?

回答

6

這裏的解決方案:

<?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 protected]>"; 

$to_name = base64_encode('Grégory Smith'); 
$to = array("=?utf-8?B?$to_name?= <[email protected]>"); 


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

?> 
+0

是,RFC 2047要求非ASCII郵件標題進行編碼。 –