Skip to content

Instantly share code, notes, and snippets.

@adam704a
Created February 7, 2013 15:02
Show Gist options
  • Save adam704a/4731454 to your computer and use it in GitHub Desktop.
Save adam704a/4731454 to your computer and use it in GitHub Desktop.
Using Sendgrid.
/*
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('player.mailer@sportsynergy.net')->
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