2013-10-12 51 views
0

我尝试使用AWS SES sendEmail方法发送邮件,并且遇到错误。我已阅读此问题:AWS SDK Guzzle error when trying to send a email with SES使用SES发送电子邮件时出现AWS SDK Guzzle错误

我正在处理一个非常类似的问题。原始海报表明他们有解决方案,但没有发布解决方案。

我的代码:

$response = $this->sesClient->sendEmail('[email protected]', 
array('ToAddresses' => array($to)), 
array('Subject.Data' => array($subject), 'Body.Text.Data' => array($message))); 

狂饮码产生的误差(从aws/Guzzle/Service/Client.php):产生

return $this->getCommand($method, isset($args[0]) ? $args[0] : array())->getResult(); 

错误:

Catchable fatal error: Argument 2 passed to Guzzle\Service\Client::getCommand() must be of the type array, string given 

综观狂饮代码,我可以看到如果设置了args[0],那么对getCommand的呼叫将发送一个字符串并且是一个字符串。如果没有设置args[0],则发送一个空数组。

我在这里错过了什么?

回答

1

解决方案: 原来我试图在SDK2代码库上使用SDK1数据结构。感谢Charlie Smith帮助我理解我做错了什么。

对于其他人(使用AWS SDK for PHP 2):

创建客户端 -

$this->sesClient = \Aws\Ses\SesClient::factory(array(
    'key' =>AWS_ACCESS_KEY_ID, 
    'secret' => AWS_SECRET_KEY, 
    'region' => Region::US_EAST_1 
)); 

现在,结构邮件(不要忘记,如果您正在使用沙箱,您需要验证任何如果您已获得生产状态,则此限制不适用) -

$from = "Example name <[email protected]>"; 
$to ="[email protected]"; 
$subject = "Testing AWS SES SendEmail()"; 

$response = $this->sesClient->getCommand('SendEmail', array(
    'Source' => $from, 
    'Destination' => array(
     'ToAddresses' => array($to) 
    ), 
    'Message' => array(
     'Subject' => array(
      'Data' => $subject 
     ), 
     'Body' => array(
      'Text' => array(
       'Data' => "Hello World!\n Testing AWS email sending." 
      ), 
      'Html' => array(
       'Data' => "<h1>Hello World!</h1><p>Testing AWS email sending</p>" 
      ) 
     ), 
    ), 
))->execute(); 

现在应该可以工作。

这是在AWS SDK的PHP 2文档的相关章节:

http://docs.aws.amazon.com/aws-sdk-php-2/latest/class-Aws.Ses.SesClient.html#_sendEmail

相关问题