Howto: Amazon SES mailer PHP

Hello!

Today I will tell how to configure send mass emails via Amazon SES from scratch.

First you need to have an account in Amazon Web Services and attached to the payment method of the service. If You have it, you can safely start!

configuring SES

So, go to the console: https://console.aws.amazon.com. In the services list, looking for SES. Since we previously had no business with SES, we were met by depressing the inscription:
image

After all the registrations and confirmations that You are not a spammer, You will receive a minimum quota limit:
the
    the
  • 10,000 letters per day
  • the
  • 5 emails per second

image

Next, we need to specify and confirm the address that will appear in the letters in the From field.
Menu Verified Senders, look for the button Verify a new sender
image

So, there is quite a bit. We need to create IAM user, to give him the right to send mail and assign a couple of keys. Come here: https://console.aws.amazon.com/iam.

Create a new group:
image

Call it:
image

In the template security policy find a ready-made template for Amazon SES Full Access:
image

Then further, further, Further and created the user group.

The next step is to create a user menu Users:
image

Create a user and immediately generated for him a pair of keys:
image

The user is created:
image

Save a couple of keys:
the
    the
  • Access Key Id: AKIAJXEPJQETZTN7HRNQ
  • Secret Access Key: /T+wQ8xSOsm8BtkWcp6kdSSaDHRJT2imn/OoE660



Add user to a group that was already created, thus giving rights to the user:
image

So, we have a pair of keys, which were given the right to send letters to the SES.

SPF record for your domain

In order to validate Amazon SES as a mailer of mail to your domain add SPF record:
v=spf1 include:amazonses.com ?all

PHP mailer

Next, copy the files from the repository github.com/korjik/PHP-SES-mailer

ses.php class to connect with SES — www.orderingdisorder.com/aws/ses
users.csv — an example of the user list in the format
"username","username@email.com"
send_email.php — the program itself is sending email.

In send_email.php need to replace the following parameters:

Key pair:
$ses = new SimpleEmailService('Access Key Id', 'Secret Access Key');

Validierung From: address
$m->setFrom('validated@email.com');

Next fill in 2 text fields — variables $text_email $html_email names are responsible for themselves.

If preparations are done, the script can be run with a parameter the path to the file users.csv:

$ php send_email.php users.csv

Summary

All the users specified in the users.csv getting emails.

Tips

Do not use validierung From address from other domains. The lack of SPF records increases the chance of emails to spam.

Tuning

As you can see, we can in each email to insert the name of user, parsed as $username=$user_fields[0] from a CSV file. Thus, you can change the CSV format, add custom fields, etc.

If you have questions, write, answer.

PS. The article is written specifically for Mr. m31.
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

March Habrameeting in Kiev

PostgreSQL load testing using JMeter, Yandex.Tank and Overload

Monitoring PostgreSQL with Zabbix