Sending Emails With Amazon SES
Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /usr/www/phpsites/public/yayprogramming/wp-content/plugins/wp-syntax/wp-syntax.php on line 383
Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /usr/www/phpsites/public/yayprogramming/wp-content/plugins/wp-syntax/wp-syntax.php on line 383
Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /usr/www/phpsites/public/yayprogramming/wp-content/plugins/wp-syntax/wp-syntax.php on line 383
Sending emails from Amazon SES can sometimes be difficult. This script will include the PHP source code to send individual emails, or mass emailing from a MySQL database. We will also be sending the email with an awesome html/css designed email template. You need to include the ses.php file. You can download ses.php from amazon.
SENDINGÂ INDIVIDUAL EMAILSÂ
Sending a basic text email through Amazon SES.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | $subject = "This is the Subject"; //put in your subject $from = "noreply@email.com"; //put in your from email address, verify on amazon ses. $addto = $email; //user email goes here $message = "This is where the message goes. Hello World!"; //basic text email message include_once('ses.php'); $con=new SimpleEmailService("API ID HERE","API KEY HERE"); //insert your api keys here $con->listVerifiedEmailAddresses(); $m = new SimpleEmailServiceMessage(); $m->addTo($addto); $m->setFrom($from); $m->setSubject($subject); $m->setMessageFromString($message,$message); $con->sendEmail($m); //sends the email |
WITH HTML MESSAGE
This will send email with an HTML template. Looks great on phones! You can download the html and css template here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | $subject = "This is the Subject"; $from = "noreply@email.com"; $addto = $email; //user email goes here ob_start(); include_once("/emails/htmlmessage.html"); // the location of your html template. Must include all CSS in the HTML. Also, images must have your full domain/location. $message = ob_get_contents(); ob_end_clean(); $subject = "This is the Subject"; $from = "noreply@email.com"; $addto = $useremail; //user email goes here $con=new SimpleEmailService(“API ID HEREâ€,â€API KEY HEREâ€); $con->listVerifiedEmailAddresses(); $m = new SimpleEmailServiceMessage(); $m->addTo($addto); $m->setFrom($from); $m->setSubject($subject); $m->setMessageFromString($message,$message); $con->sendEmail($m); echo “Email sent to: $addtoâ€; |
Mass HTML Email Sending
Not much of a difference, this script will send an HTML email to all users in the MySQL database. Create a while loop that goes through all users.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | $subject = "This is the Subject"; $from = "noreply@email.com"; $addto = $email; //user email goes here ob_start(); include_once("/emails/htmlmessage.html"); // the location of your html template. Must include all CSS in the HTML. Also, images must have your full domain/location. $message = ob_get_contents(); ob_end_clean(); $qryget = mysql_query("SELECT * FROM users ORDER BY id DESC") or die (mysql_error()); while($row = mysql_fetch_array($qryget)){ $useremail= $row['email']; $subject = "This is the Subject"; $from = "noreply@email.com"; $addto = $useremail; //user email goes here $con=new SimpleEmailService(“API ID HEREâ€,â€API KEY HEREâ€); $con->listVerifiedEmailAddresses(); $m = new SimpleEmailServiceMessage(); $m->addTo($addto); $m->setFrom($from); $m->setSubject($subject); $m->setMessageFromString($message,$message); $con->sendEmail($m); echo “Email sent to: $addtoâ€; } |
Have a question? comment and i’ll check out your situation. Please remember to have CURL installed and enabled in PHP settings.