0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Amazon SESを用いてHTMLメールを送信する

Posted at

SDKをインストールする

composer require aws/aws-sdk-php

SDKを用いたコード

use Aws\Ses\Exception\SesException;
use Aws\Ses\SesClient;


$ses = new SesClient([
    'profile' => 'default',
    'region'  => 'us-west-2', //任意のもの
    'version' => '2010-12-01'
])

//送信対象のメールのリスト
$mailList = ['aaa@aaa.com', 'bbb@bbb.com'];

//HTMlメールのボディ
$html = '<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>';

//件名
$subject = 'test'

try {
    $result = $ses->sendEmail([
        'Destination' => [
            'ToAddresses' => [$mailList],
        ],
        'Source' => 'ccc@ccc.com',
        'Message' => [
            'Body' => [
                'Html' => [
                    'Charset' => 'utf-8',
                    'Data' => $html,
                ],
            ],
            'Subject' => [
                'Charset' => 'utf-8',
                'Data' => $subject,
            ],
        ],
    ]);
    echo $result['MessageId'];
} catch (SesException $e) {
    echo $e->getMessage();
}

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?