安装SDK:
https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/getting-started_installation.html
发送demo代码:
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/examples-send-using-sdk.html
准备好key, sec
use Aws\Ses\SesClient; use Aws\Exception\AwsException; $credentials = new Aws\Credentials\Credentials('xx', 'xx'); $SesClient = new SesClient([ 'version' => '2010-12-01', 'region' => 'us-east-1', 'credentials' => $credentials, ]); $sender_email = '[email protected]'; $recipient_emails = ['[email protected]']; $subject = 'Amazon SES test (AWS SDK for PHP)'; $plaintext_body = 'This email was sent with Amazon SES using the AWS SDK for PHP.' ; $html_body = '<h1>AWS Amazon Simple Email Service Test Email</h1>'. '<p>This email was sent with <a href="https://aws.amazon.com/ses/">'. 'Amazon SES</a> using the <a href="https://aws.amazon.com/sdk-for-php/">'. 'AWS SDK for PHP</a>.</p>'; $char_set = 'UTF-8'; try { $result = $SesClient->sendEmail([ 'Destination' => [ 'ToAddresses' => $recipient_emails, ], 'ReplyToAddresses' => [$sender_email], 'Source' => $sender_email, 'Message' => [ 'Body' => [ 'Html' => [ 'Charset' => $char_set, 'Data' => $html_body, ], 'Text' => [ 'Charset' => $char_set, 'Data' => $plaintext_body, ], ], 'Subject' => [ 'Charset' => $char_set, 'Data' => $subject, ], ], ]); $messageId = $result['MessageId']; echo("Email sent! Message ID: $messageId"."\n"); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo("The email was not sent. Error message: ".$e->getAwsErrorMessage()."\n"); echo "\n"; }
对于使用php比较老的版本,可以用这个第三方实现库。
https://github.com/daniel-zahariev/php-aws-ses