AWS SDK for PHP
Developer Guide

Managing Email Filters Using the Amazon SES API and the AWS SDK for PHP Version 3

In addition to sending emails, you can also receive email with Amazon Simple Email Service (Amazon SES). An IP address filter enables you to optionally specify whether to accept or reject mail that originates from an IP address or range of IP addresses. For more information, see Managing IP Address Filters for Amazon SES Email Receiving.

The following examples show how to:

All the example code for the AWS SDK for PHP Version 3 is available here on GitHub.

Credentials

Before running the example code, configure your AWS credentials, as described in Credentials for the AWS SDK for PHP Version 3. Then import the AWS SDK for PHP, as described in Basic Usage Patterns of the AWS SDK for PHP Version 3.

For more information about using Amazon SES, see the Amazon SES Developer Guide.

Create an Email Filter

To allow or block emails from a specific IP address, use the CreateReceiptFilter operation. Provide the IP address or range of addresses and a unique name to identify this filter.

Imports

require 'vendor/autoload.php'; use Aws\SES\SESClient; use Aws\Exception\AwsException;

Sample Code

$SesClient = new Aws\SES\SESClient([ 'profile' => 'default', 'version' => '2010-12-01', 'region' => 'us-east-2' ]); $filter_name = 'FilterName'; $ip_address_range = '10.0.0.1/24'; try { $result = $SesClient->createReceiptFilter([ 'Filter' => [ 'IpFilter' => [ 'Cidr' => $ip_address_range, 'Policy' => 'Block|Allow', ], 'Name' => $filter_name, ], ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }

List All Email Filters

To list the IP address filters associated with your AWS account in the current AWS Region, use the ListReceiptFilters operation.

Imports

require 'vendor/autoload.php'; use Aws\SES\SESClient; use Aws\Exception\AwsException;

Sample Code

$SesClient = new Aws\SES\SESClient([ 'profile' => 'default', 'version' => '2010-12-01', 'region' => 'us-east-2' ]); try { $result = $SesClient->listReceiptFilters([ ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }

Delete an Email Filter

To remove an existing filter for a specific IP address use the DeleteReceiptFilter operation. Provide the unique filter name to identify the receipt filter to delete.

If you need to change the range of addresses that are filtered, you can delete a receipt filter and create a new one.

Imports

require 'vendor/autoload.php'; use Aws\SES\SESClient; use Aws\Exception\AwsException;

Sample Code

$SesClient = new Aws\SES\SESClient([ 'profile' => 'default', 'version' => '2010-12-01', 'region' => 'us-east-2' ]); $filter_name = 'FilterName'; try { $result = $SesClient->deleteReceiptFilter([ 'FilterName' => $filter_name, ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }