Created
February 7, 2013 15:02
-
-
Save adam704a/4731454 to your computer and use it in GitHub Desktop.
Using Sendgrid.
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
/* | |
Uses sendgrid to send out system generated emails. Check out Sendgrid.com | |
*/ | |
function sendgrid_email($subject, $to_emails, $content, $category){ | |
if (isDebugEnabled(1)) { | |
logMessage("applicationlib.sendgrid_email: sending email with subject $subject with a size " . count($to_emails) ); | |
} | |
if (isDebugEnabled(1)) { | |
logMessage("applicationlib.sendgrid_email: sending email to: " ); | |
} | |
// To make backwards compatible with postageapp create | |
$toList = array(); | |
$nameList = array(); | |
foreach ($to_emails as $k=>$v){ | |
if (isDebugEnabled(1)) { | |
logMessage("applicationlib.sendgrid_email: sending email to: $k with subject $subject and cateogry $category" ); | |
} | |
$toList[] = $k; | |
$nameList[] = $v['name']; | |
} | |
$sendgrid = new SendGrid($_SESSION["CFG"]["sendgriduser"], $_SESSION["CFG"]["sendgridpass"]); | |
$file_contents = file_get_contents($_SESSION["CFG"]["templatedir"]."/email/standard.email.html"); | |
$template = str_replace("%clubname%", $content->clubname, $file_contents); | |
$template = str_replace("%sitecode%", get_sitecode(), $template); | |
$template = str_replace("%content%", $content->line1, $template); | |
$template = str_replace("%dns%", $_SESSION["CFG"]["dns"], $template); | |
$template = str_replace("%app_root%", $_SESSION["CFG"]["wwwroot"], $template); | |
$mail = new SendGrid\Mail(); | |
$mail-> | |
setFrom('[email protected]')-> | |
setFromName('Sportsynergy')-> | |
setSubject($subject)-> | |
setText($content->line1)-> | |
addCategory($category)-> | |
addCategory($content->clubname)-> | |
setTos($toList)-> | |
setHtml($template)-> | |
addSubstitution("%firstname%", $nameList); | |
$sendgrid->smtp->send($mail); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment