Last active
April 18, 2017 06:51
-
-
Save kilitbilgi/f697898339e3e751c32c735ac9c4ba1d to your computer and use it in GitHub Desktop.
Send emails with Amazon SNS in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Include PHP Mailer -> https://github.com/PHPMailer/PHPMailer | |
require_once(APPPATH.'libraries/phpmailer/PHPMailerAutoload.php'); | |
//Send email with Amazon SNS | |
function sendMail($data){ | |
$from_email = $data["from_email"]; | |
$from_name = $data["from_name"]; | |
$to_email = $data["to_email"]; | |
$to_name = $data["to_name"]; | |
$subject = $data["subject"]; | |
$body = $data ["body"]; | |
$attachmentIncluded = $data["attachmentIncluded"]; | |
//Create a new PHPMailer instance | |
$mail = new PHPMailer; | |
//Tell PHPMailer to use SMTP | |
$mail->isSMTP(); | |
//You can set your region according to your account. Ex:eu-east-1 | |
$mail->Host = 'email-smtp.eu-west-1.amazonaws.com'; | |
$mail->Port = 587; | |
//Set the encryption system to use - ssl (deprecated) or tls | |
$mail->SMTPSecure = 'tls'; | |
//Whether to use SMTP authentication | |
$mail->SMTPAuth = true; | |
//Username to use for SMTP authentication - use full email address for gmail | |
$mail->Username = AWS_SES_API_KEY; | |
//Password to use for SMTP authentication | |
$mail->Password = AWS_SES_SECRET_KEY; | |
//Set who the message is to be sent from | |
$mail->setFrom($from_email, $from_name); | |
//Set who the message is to be sent to | |
$mail->addAddress($to_email, $to_name); | |
//Set the subject line | |
$mail->Subject = $subject; | |
$mail->Body = $body; | |
$mail->IsHTML(true); | |
if($attachmentIncluded) { | |
$attachment = $data["attachment"]; | |
$mail->addAttachment($attachment); | |
} | |
//send the message, check for errors | |
if (!$mail->send()) { | |
return $mail->ErrorInfo; | |
}else { | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is example request of how its done