SendIt.php

SendIt.php

Summary

SendIt.php is a convenience class for php developers to send email and text messages using PHPMailer and/or AWS SNS or SES.

Dependencies

PHPMailer: https://github.com/PHPMailer/PHPMailer

Amazon AWS PHP Client Library (v2): http://docs.aws.amazon.com/aws-sdk-php/v2/guide/installation.html

Amazon AWS PHP Client Library (v3): Soon to be supported

Config File

We recommend including your credentials by including a config file where you define constants to use elsewhere:

<?php
	define("aws_key", "AKIAIIQ7653EUYUCKTQA");
	define("aws_secret", "e4NFh5QrRfBoqpcUMhXvXX0IthR0RFrlqiAIx3AT");
	define("aws_region", "us-east-1");

	//Text Messages - Amazon SNS
	define("aws_snsARN", "arn:aws:sns:us-east-1:413531569768:AutomatedMessages");

	//Emailing
	define("emailMethod", "aws");  //"aws" or "smtp"
	define("systemEmail", "you@awesome.com");
	define("systemEmailDispName", "Your Name");
	define("aws_sesARN", "arn:aws:ses:us-east-1:413515975368:identity/you@awesome.com");

	/* Amazon SMTP Example
	define("smtpHost", "email-smtp.us-east-1.amazonaws.com");
	define("smtpUsername", "RETAJVKHW7EQWRISBSQQ");
	define("smtpPassword", "AjOgwKte85s6Q156DcOU+YN7hnsdI/SwFTsUOfdd6xUN");
	*/
	
	/*  1and1 Email SMTP Example
	define("smtpHost", "smtp.1and1.com");
	define("smtpUsername", "your@company.com"); 
	define("smtpPassword", "yourpass765"); 
	*/
?>

Usage

<?php
	$dir = dirname(__FILE__);
	include $dir . "/creds.php";
	include $dir . "/awsPHP/aws-autoloader.php";
	use Aws\Sns\SnsClient;
	include $dir . "/SendIt.php";
	
	$sender = new SendIt(array(
		"aws_key"=>aws_key,
		"aws_secret"=>aws_secret,
		"aws_region"=>aws_region,
		//For Emailing
		"emailMethod"=>emailMethod, //smtp or aws
		"aws_sesARN"=>aws_sesARN,
		//For Text Messages
		"aws_snsARN"=>aws_snsARN,
		"aws_snsSenderId"=>aws_snsSenderId
	));
	$sender->TextMessage(array(
		"phoneNumber"=>"+11239832886",
		"subject"=>"this is an important test",
		"message"=>"Gotta get this message through"
	));
	$sender->Email(array(
		"to"=>"tom@lovetech.io",
		"from"=>systemEmail,
		"from"=>systemEmailDispName,
		"subject"=>"This is an important test",
		"message"=>"Gotta get this message through"
	));
?>

Download for More Fun:

file_downloadSendIt.php

Explore Chakra7 Today