

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# Amazon SES API 및 AWS SDK for PHP 버전 3을 사용하여 사용자 지정 이메일 템플릿 생성
<a name="ses-template"></a>

Amazon Simple Email Service (Amazon SES)를 통해 템플릿을 사용하여 각 수신자에 대해 맞춤화된 이메일을 전송할 수 있습니다. 템플릿에는 제목 줄과 이메일 본문의 텍스트 및 HTML 부분이 포함됩니다. 제목과 본문 섹션에는 각 수신자에 대해 맞춤화된 고유 값이 포함될 수도 있습니다.

자세한 내용은 Amazon Simple Email Service 개발자 가이드에서 [Amazon SES를 사용하여 개인화된 이메일 전송](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-personalized-email-api.html)을 참조하세요.

다음 예제에서는 다음과 같은 작업을 하는 방법을 보여줍니다.
+ [CreateTemplate](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-email-2010-12-01.html#createtemplate)을 사용하여 이메일 템플릿 만들기
+ [ListTemplates](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-email-2010-12-01.html#listtemplates)를 사용하여 모든 이메일 템플릿 나열
+ [GetTemplate](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-email-2010-12-01.html#gettemplate)을 사용하여 이메일 템플릿 검색
+ [UpdateTemplate](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-email-2010-12-01.html#updateTemplate)을 사용하여 이메일 템플릿 업데이트
+ [DeleteTemplate](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-email-2010-12-01.html#deletetemplate)을 사용하여 이메일 템플릿 제거
+ [SendTemplatedEmail](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-email-2010-12-01.html#sendtemplatedemail)을 사용하여 템플릿 이메일 전송

AWS SDK for PHP에 대한 모든 예제 코드는 [GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/php/example_code)에서 사용할 수 있습니다.

## 보안 인증 정보
<a name="examplecredentials"></a>

예제 코드를 실행하기 전에 [AWS SDK for PHP 버전 3을 AWS 사용하여 로 인증](credentials.md)에 설명된 대로 AWS 보안 인증을 구성합니다. 그 다음 [AWS SDK for PHP 버전 3 설치](getting-started_installation.md)에 설명된 대로 AWS SDK for PHP를 가져옵니다.

Amazon SES 사용에 대한 자세한 내용은 [Amazon SES 개발자 안내서](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/)를 참조하세요.

## 이메일 템플릿 생성
<a name="create-an-email-template"></a>

템플릿을 만들어 맞춤형 이메일 메시지를 전송하려면 [CreateTemplate](https://docs.aws.amazon.com/ses/latest/APIReference/API_CreateTemplate.html) 작업을 사용합니다. 템플릿은 해당 템플릿이 추가된 AWS 리전에서 메시지를 보낼 권한이 있는 계정이 사용할 수 있습니다.

**참고**  
Amazon SES는 HTML의 유효성을 검사하지 않으므로 이메일을 전송하기 전에 *HtmlPart*가 유효한지 확인해야 합니다.

 **가져옵니다**.

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
```

 **샘플 코드** 

```
$SesClient = new Aws\Ses\SesClient([
    'profile' => 'default',
    'version' => '2010-12-01',
    'region' => 'us-east-2'
]);

$name = 'Template_Name';
$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>';
$subject = 'Amazon SES test (AWS SDK for PHP)';
$plaintext_body = 'This email was send with Amazon SES using the AWS SDK for PHP.';

try {
    $result = $SesClient->createTemplate([
        'Template' => [
            'HtmlPart' => $html_body,
            'SubjectPart' => $subject,
            'TemplateName' => $name,
            'TextPart' => $plaintext_body,
        ],
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}
```

## 이메일 템플릿 가져오기
<a name="get-an-email-template"></a>

제목 줄, HTML 본문 및 일반 텍스트를 포함하여 기존 이메일 템플릿의 콘텐츠를 보려면 [GetTemplate](https://docs.aws.amazon.com/ses/latest/APIReference/API_GetTemplate.html) 작업을 사용합니다. TemplateName만 필수입니다.

 **가져옵니다**.

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
```

 **샘플 코드** 

```
$SesClient = new Aws\Ses\SesClient([
    'profile' => 'default',
    'version' => '2010-12-01',
    'region' => 'us-east-2'
]);

$name = 'Template_Name';

try {
    $result = $SesClient->getTemplate([
        'TemplateName' => $name,
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}
```

## 모든 이메일 템플릿 나열
<a name="list-all-email-templates"></a>

현재 AWS 리전의 AWS 계정 계정과 연결된 모든 이메일 템플릿의 목록을 검색하려면 [ListTemplates](https://docs.aws.amazon.com/ses/latest/APIReference/API_ListTemplates.html) 작업을 사용합니다.

 **가져옵니다**.

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
```

 **샘플 코드** 

```
$SesClient = new Aws\Ses\SesClient([
    'profile' => 'default',
    'version' => '2010-12-01',
    'region' => 'us-east-2'
]);

try {
    $result = $SesClient->listTemplates([
        'MaxItems' => 10,
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}
```

## 이메일 템플릿 업데이트
<a name="update-an-email-template"></a>

제목 줄, HTML 본문 및 일반 텍스트를 포함하여 특정 이메일 템플릿의 콘텐츠를 변경하려면 [UpdateTemplate](https://docs.aws.amazon.com/ses/latest/APIReference/API_UpdadteTemplate.html) 작업을 사용합니다.

 **가져옵니다**.

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
```

 **샘플 코드** 

```
$SesClient = new Aws\Ses\SesClient([
    'profile' => 'default',
    'version' => '2010-12-01',
    'region' => 'us-east-2'
]);

$name = 'Template_Name';
$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>';
$subject = 'Amazon SES test (AWS SDK for PHP)';
$plaintext_body = 'This email was send with Amazon SES using the AWS SDK for PHP.';

try {
    $result = $SesClient->updateTemplate([
        'Template' => [
            'HtmlPart' => $html_body,
            'SubjectPart' => $subject,
            'TemplateName' => $name,
            'TextPart' => $plaintext_body,
        ],
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}
```

## 이메일 템플릿 삭제
<a name="delete-an-email-template"></a>

특정 이메일 템플릿을 제거하려면 [DeleteTemplate](https://docs.aws.amazon.com/ses/latest/APIReference/API_DeleteTemplate.html) 작업을 사용합니다. TemplateName만 필요합니다.

 **가져옵니다**.

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
```

 **샘플 코드** 

```
$SesClient = new Aws\Ses\SesClient([
    'profile' => 'default',
    'version' => '2010-12-01',
    'region' => 'us-east-2'
]);

$name = 'Template_Name';

try {
    $result = $SesClient->deleteTemplate([
        'TemplateName' => $name,
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}
```

## 템플릿이 있는 이메일 전송
<a name="send-an-email-with-a-template"></a>

템플릿을 사용하여 수신자에게 이메일을 전송하려면 [SendTemplatedEmail](https://docs.aws.amazon.com/ses/latest/APIReference/API_SendTemplatedEmail.html) 작업을 사용합니다.

 **가져옵니다**.

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
```

 **샘플 코드** 

```
$SesClient = new Aws\Ses\SesClient([
    'profile' => 'default',
    'version' => '2010-12-01',
    'region' => 'us-east-2'
]);

$template_name = 'Template_Name';
$sender_email = 'email_address';
$recipient_emails = ['email_address'];

try {
    $result = $SesClient->sendTemplatedEmail([
        'Destination' => [
            'ToAddresses' => $recipient_emails,
        ],
        'ReplyToAddresses' => [$sender_email],
        'Source' => $sender_email,

        'Template' => $template_name,
        'TemplateData' => '{ }'
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}
```