To create a PHP script to sent email using Amazon SES, create a folder
mkdir ses-test cd ses-test
Install phpMailer using composer
composer require phpmailer/phpmailer
Create a PHP file with following content
SMTPDebug = 2; $mail->isSMTP(); $mail->Host = 'email-smtp.us-east-1.amazonaws.com'; // YOUR SES END POINT $mail->SMTPAuth = true; $mail->Username = 'AKIAJSKJUHBOU2ARXVLQ'; // SMTP Username $mail->Password = 'AjMmd3gRkmTyCY2QoCDkWmkGKA345zuhseS7gV0X6uz0'; // SMTP Password $mail->SMTPSecure = 'tls'; $mail->Port = 587; //Recipients $mail->setFrom('info@YOUR_SES_VERIFIED_DOMAIN.com', 'YOUR_SES_VERIFIED_DOMAIN.com'); $mail->addAddress('[email protected]', 'Your Name'); // If your SES is in Sandbox, you need to verify your email. $mail->addReplyTo('info@YOUR_SES_VERIFIED_DOMAIN.com', 'YOUR_SES_VERIFIED_DOMAIN.com'); //Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'Here is the subject'; $mail->Body = 'This is the HTML message body in bold!'; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; $mail->send(); echo 'Message has been sent'; } catch (Exception $e) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; }
Now test it by running
root@ok:~/ses-test# php 1.php 2018-01-15 08:45:54 SERVER -> CLIENT: 220 email-smtp.amazonaws.com ESMTP SimpleEmailService-2762711029 fDkTVziQIcNhSCkxwSpA 2018-01-15 08:45:54 CLIENT -> SERVER: EHLO ok 2018-01-15 08:45:54 SERVER -> CLIENT: 250-email-smtp.amazonaws.com 250-8BITMIME 250-SIZE 10485760 250-STARTTLS 250-AUTH PLAIN LOGIN 250 Ok 2018-01-15 08:45:54 CLIENT -> SERVER: STARTTLS 2018-01-15 08:45:54 SERVER -> CLIENT: 220 Ready to start TLS 2018-01-15 08:45:54 CLIENT -> SERVER: EHLO ok 2018-01-15 08:45:54 SERVER -> CLIENT: 250-email-smtp.amazonaws.com 250-8BITMIME 250-SIZE 10485760 250-STARTTLS 250-AUTH PLAIN LOGIN 250 Ok 2018-01-15 08:45:54 CLIENT -> SERVER: AUTH LOGIN 2018-01-15 08:45:54 SERVER -> CLIENT: 334 VXNlcm5hbWU6 2018-01-15 08:45:54 CLIENT -> SERVER:2018-01-15 08:45:54 SERVER -> CLIENT: 334 UGFzc3dvcmQ6 2018-01-15 08:45:54 CLIENT -> SERVER: 2018-01-15 08:45:54 SERVER -> CLIENT: 235 Authentication successful. 2018-01-15 08:45:54 CLIENT -> SERVER: MAIL FROM: 2018-01-15 08:45:54 SERVER -> CLIENT: 250 Ok 2018-01-15 08:45:54 CLIENT -> SERVER: RCPT TO: 2018-01-15 08:45:54 SERVER -> CLIENT: 250 Ok 2018-01-15 08:45:54 CLIENT -> SERVER: DATA 2018-01-15 08:45:54 SERVER -> CLIENT: 354 End data with . 2018-01-15 08:45:54 CLIENT -> SERVER: Date: Mon, 15 Jan 2018 03:45:54 -0500 2018-01-15 08:45:54 CLIENT -> SERVER: To: Yujin Boby 2018-01-15 08:45:54 CLIENT -> SERVER: From: "hostonnet.com" 2018-01-15 08:45:54 CLIENT -> SERVER: Reply-To: "hostonnet.com" 2018-01-15 08:45:54 CLIENT -> SERVER: Subject: Here is the subject 2018-01-15 08:45:54 CLIENT -> SERVER: Message-ID: <4Px5PcyItpZIBJeyp03zA7sVd6uBkNPwuctLKMLeU4@ok> 2018-01-15 08:45:54 CLIENT -> SERVER: X-Mailer: PHPMailer 6.0.3 (https://github.com/PHPMailer/PHPMailer) 2018-01-15 08:45:54 CLIENT -> SERVER: MIME-Version: 1.0 2018-01-15 08:45:54 CLIENT -> SERVER: Content-Type: multipart/alternative; 2018-01-15 08:45:54 CLIENT -> SERVER: boundary="b1_4Px5PcyItpZIBJeyp03zA7sVd6uBkNPwuctLKMLeU4" 2018-01-15 08:45:54 CLIENT -> SERVER: Content-Transfer-Encoding: 8bit 2018-01-15 08:45:54 CLIENT -> SERVER: 2018-01-15 08:45:54 CLIENT -> SERVER: This is a multi-part message in MIME format. 2018-01-15 08:45:54 CLIENT -> SERVER: --b1_4Px5PcyItpZIBJeyp03zA7sVd6uBkNPwuctLKMLeU4 2018-01-15 08:45:54 CLIENT -> SERVER: Content-Type: text/plain; charset=us-ascii 2018-01-15 08:45:54 CLIENT -> SERVER: 2018-01-15 08:45:54 CLIENT -> SERVER: This is the body in plain text for non-HTML mail clients 2018-01-15 08:45:54 CLIENT -> SERVER: 2018-01-15 08:45:54 CLIENT -> SERVER: --b1_4Px5PcyItpZIBJeyp03zA7sVd6uBkNPwuctLKMLeU4 2018-01-15 08:45:54 CLIENT -> SERVER: Content-Type: text/html; charset=us-ascii 2018-01-15 08:45:54 CLIENT -> SERVER: 2018-01-15 08:45:54 CLIENT -> SERVER: This is the HTML message body in bold! 2018-01-15 08:45:54 CLIENT -> SERVER: 2018-01-15 08:45:54 CLIENT -> SERVER: 2018-01-15 08:45:54 CLIENT -> SERVER: --b1_4Px5PcyItpZIBJeyp03zA7sVd6uBkNPwuctLKMLeU4-- 2018-01-15 08:45:54 CLIENT -> SERVER: 2018-01-15 08:45:54 CLIENT -> SERVER: . 2018-01-15 08:45:55 SERVER -> CLIENT: 250 Ok 01000160f8ff15ea-af0d4268-6c9e-43ee-8bbb-4081917f75d6-000000 2018-01-15 08:45:55 CLIENT -> SERVER: QUIT 2018-01-15 08:45:55 SERVER -> CLIENT: 221 Bye Message has been sentroot@ok:~/ses-test#