Send emails through AWS SES from console using SwiftMailer

Table of Content

Testing Email Sending Using the Command Line

Verifying a Domain With Amazon SES

Setting Up Easy DKIM for a Domain

Can I use Amazon’s SES with Symfony2 and the Swiftmailer Bundle?

Swiftmailer Spooling and Handling Failures

Problems with Emails Received from Amazon SES

Final script for check email sending

<?php
require __DIR__ . '/vendor/autoload.php';

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;

umask(0000);

$loader = require __DIR__ . '/app/autoload.php';
Debug::enable();

// Run bootstrap
$kernel = new AppKernel('prod', true);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$kernel->boot();

$container = $kernel->getContainer();
$container->enterScope('request');
$container->set('request', $request);

/** @var $mailer \Swift_Mailer */
$mailer = $container->get('mailer');

$transport = \Swift_SmtpTransport::newInstance('email-smtp.eu-central-1.amazonaws.com', 587, 'tls')
    ->setUsername('AWS_ACCESS_KEY')
    ->setPassword('AWS_SECRET_KEY');

// Create a message
$message = Swift_Message::newInstance($transport)
    ->setFrom('sender@example.com')
    ->setTo('recipient@example.net')
    ->setSubject('Amazon SES SMTP Test')
    ->setBody('This message was sent using the Amazon SES SMTP interface.');

// Send the message
$result = $mailer->send($message);

Run the script

php send-email.php

Leave a Reply

Your email address will not be published. Required fields are marked *