简体   繁体   中英

How to send an email through AWS simple email service(ses) using signature version 4 in PHP

Currently I'm sending email through AWS SDK SES signature 3 and got an email from Amazon to upgrade it to SES signature version 4. But where to add signature in AWS SDK? below is the current code that is being used to send emails.

<?php
//SES
$SESCredentials = array(
    'key' => awsSESAccessKey,
    'secret' => awsSESSecretKey
);

$SESClient = new SesClient([
    // 'profile' => 'default',
    'version' => AWS_SDK_VERSION,
    'region' => AWS_REGION,
    'http' => [
            'verify' => AWS_CERT_PATH
    ],
    'credentials' => $SESCredentials
]);


$result = $SESClient->sendEmail([
            'Destination' => [
                'ToAddresses' => $recipient_emails
            ],
            'ReplyToAddresses' => [$sender_email],
            'Source' => $sender_email,
            'Message' => [
                'Body' => [
                    'Html' => [
                        'Charset' => $char_set,
                        'Data' => $html_body
                    ]
                ],
                'Subject' => [
                    'Charset' => $char_set,
                    'Data' => $subject,
                ]
            ]                
        ]);
?>

You can use this package as it supports signature 4

https://github.com/daniel-zahariev/php-aws-ses

$signature_version = SimpleEmailService::REQUEST_SIGNATURE_V4;
$ses = new SimpleEmailService('AccessKey', 'SecretKey', $region_endpoint, 

$trigger_error, $signature_version);
$m->addTo('Recipient Name <recipient@example.com>');
$m->setFrom('Sender <user@example.com>');
$m->setSubject('Hello, world!');
$m->setMessageFromString('This is the message body.');

$ses = new SimpleEmailService('AccessKey', 'SecretKey');
print_r($ses->sendEmail($m));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM