📜 ⬆️ ⬇️

Howto: Amazon SES PHP mailer

Hello!

Today, I’ll tell you how to set up bulk mailing through Amazon SES from scratch.

First you need to have an account in Amazon Web Services and a service payment method attached to it. If you have it, we can safely begin!
')
SES Setup

So, let's go to the console: https://console.aws.amazon.com . In the list of services we are looking for SES. Because we have not dealt with SES before, we are met by a depressing inscription:
image

After all registrations and confirmations that you are not a spammer, you will receive the minimum limits for sending:

image

Next, we need to specify and confirm the address, which will be indicated in the letters in the From field.
In the Verified Senders menu, look for the Verify a new sender button
image

So, it remains quite a bit. We have to create an IAM user, give him the right to send mail and assign him a pair of keys. Go here: https://console.aws.amazon.com/iam .

Create a new group:
image

Call her:
image

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

After that, Next, Next, Next, and created a user group.

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

Create a user and immediately generate a pair of keys for it:
image

User created:
image

Save a pair of his keys:


Add a user to the group that was created before, thereby giving the user rights:
image

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

SPF record for domain

To validate Amazon SES as a mail sender, add an SPF record to your domain:
v = spf1 include: amazonses.com? all

Php mailer

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

ses.php - class for connecting with SES - www.orderingdisorder.com/aws/ses
users.csv - sample list of users in the format
"Username", "username@email.com"
send_email.php - mail distribution program itself.

In send_email.php, you need to replace the following parameters:

A couple of keys:
$ ses = new SimpleEmailService (' Access Key Id ', ' Secret Access Key ');

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

Next, fill in 2 text fields - the variables $ text_email and $ html_email are responsible for themselves with names.

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

$ php send_email.php users.csv

Total

All users listed in users.csv will receive emails.

Tips

Do not use a validated From address from foreign domains. The absence of SPF records increases the chance of emails getting into spam.

Tuning

As you have noticed, we can insert the user name, read as $ username = $ user_fields [0] from the CSV file into each letter. Thereby, you yourself can change the CSV format, add custom fields, etc.

If you have questions, write, I will answer.

Shl. The article was written specifically for Mr. m31 .

Source: https://habr.com/ru/post/141102/


All Articles