如何通过laravel发送电子邮件?

时间:2017-03-24 14:31:07

标签: php laravel email amazon-web-services laravel-5

我使用一个函数发送电子邮件,这包含发送的html.I搜索文档,我尝试安装"guzzlehttp/guzzle": "~5.3|~6.0""aws/aws-sdk-php": "~3.0"这是我的功能:

function enviarCorreo(Request $request){
    $myArray =$request->get('htmls');
    $registers =json_decode($myArray,true);

    foreach ($registers as $value) {
        $client = SesClient::factory(array(
                'version'=> 'latest',
                'region' => 'us-east-1',
                'credentials' => [
        'key'    => 'something',
        'secret' => 'something',
    ]
        ));

    $request = array();
    $request['Source'] = "info@tenebit.com.co";
    $request['Destination']['ToAddresses'] =  array("sebastian.moncada@tenebit.com.co");
    $request['Message']['Subject']['Data'] = "Cambio Precio";
    $request['Message']['Body']['Text']['Data'] = "hola";

    $client->sendEmail($request);
    }
}

当我执行此功能时,我收到错误:

Error executing "SendEmail" on "https://email.us-east-1.amazonaws.com"; AWS HTTP error: Client error: `POST https://email.us-east-1.amazonaws.com` resulted in a `403 Forbidden` response:
<ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<Error>
<Type>Sender</Type>
<Code>SignatureDo (truncated...)
SignatureDoesNotMatch (client): The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

The Canonical String for this request should have been
'POST
/

aws-sdk-invocation-id:6e193a6cd1a8f79ff9431f8a578fd33c
aws-sdk-retry:0/0
host:email.us-east-1.amazonaws.com
x-amz-date:20170323T234114Z

aws-sdk-invocation-id;aws-sdk-retry;host;x-amz-date
b4a0fc6dfb3b8b956012d7ea58727e0f2674c24ecec5ca7cc7aa58151169fc2e'

The String-to-Sign should have been
'AWS4-HMAC-SHA256
20170323T234114Z
20170323/us-east-1/ses/aws4_request
90bda171b5066152e79af1168f8a107aa8f1255f38d1fe261efb757173b0e81c'
- <ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<Error>
<Type>Sender</Type>
<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

The Canonical String for this request should have been
'POST
/

aws-sdk-invocation-id:6e193a6cd1a8f79ff9431f8a578fd33c
aws-sdk-retry:0/0
host:email.us-east-1.amazonaws.com
x-amz-date:20170323T234114Z

aws-sdk-invocation-id;aws-sdk-retry;host;x-amz-date
b4a0fc6dfb3b8b956012d7ea58727e0f2674c24ecec5ca7cc7aa58151169fc2e'

The String-to-Sign should have been
'AWS4-HMAC-SHA256
20170323T234114Z
20170323/us-east-1/ses/aws4_request
90bda171b5066152e79af1168f8a107aa8f1255f38d1fe261efb757173b0e81c'
</Message>
</Error>
<RequestId>3487b258-1022-11e7-b9c4-8fda0cb028e9</RequestId>
</ErrorResponse>

AND

ClientException in RequestException.php line 111:
Client error: `POST https://email.us-east-1.amazonaws.com` resulted in a `403 Forbidden` response:
<ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<Error>
<Type>Sender</Type>
<Code>SignatureDo (truncated...)

感谢您就如何解决问题给出答案。

0 个答案:

没有答案