Skip to content

Instantly share code, notes, and snippets.

@bnvk
Created November 16, 2010 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bnvk/702485 to your computer and use it in GitHub Desktop.
Save bnvk/702485 to your computer and use it in GitHub Desktop.
// Creates Object & arrays
$hdr = new SmtpApiHeader();
$toList = array();
$nameList = array();
$pubkeyList = array();
$BurstCount = 0;
// Loop Que
do {
$BurstCount++;
// Add Arrays
$toList[] = $row_ListQue['email'];
$nameList[] = $row_ListQue['name'];
$pubkeyList[] = $row_ListQue['pub_key'];
// Delete from que
$deleteSQL = "DELETE FROM lists_sending_que WHERE list_sending_id=".$row_ListQue['list_sending_id'];
$ResultDelete = mysql_query($deleteSQL, $db) or die(mysql_error());
} while ($row_ListQue = mysql_fetch_assoc($ListQue));
// Set all of the above variables
$hdr->addTo($toList);
$hdr->addSubVal('-email-', $toList);
$hdr->addSubVal('-name-', $nameList);
$hdr->addSubVal('-pubkey-', $pubkeyList);
// Filter Footer
$hdr->addFilterSetting('footer', 'enable', 1);
$hdr->addFilterSetting('footer', "text/html", "<b>Thank you for your business</b>");
$hdr->addFilterSetting('footer', "text/plain", "Thank you for your business");
// Filter Subscriton
$hdr->addFilterSetting('subscriptiontrack', 'enable', 1);
$hdr->addFilterSetting('subscriptiontrack', 'text/html', '<% Click here to safely unsubscribe %>');
$hdr->addFilterSetting('subscriptiontrack', 'text/plain', '<% Click here to safely unsubscribe %>');
$hdr->addFilterSetting('subscriptiontrack', 'url', 'http://trackersearth.com/');
$hdr->addFilterSetting('subscriptiontrack', 'landing', 'http://domain.com/lists/unsubscribe');
// Subject of email
$subject = $row_ListMessage['message_subject'];
// Where is this message coming from.
$from = array('lists@domain.com' => 'My Site');
// If you dont specify a sender list above, you can specifiy the user here.
// If a sender list IS specified above this email address becomes irrelevant.
$to = array('lists@domain.com' => 'My Site');
$text = $row_ListMessage['message_txt'];
$html = "<html><head>".$row_ListMessage['message_subject']."</head><body><p>Hi -name-, you are getting this email because you are subscribed to ".$row_List['name']."</p>".$row_ListMessage['message_txt']."<hr></body></html>";
// Create new swift connection and authenticate
$transport = Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 25);
$transport->setUsername('account@tsendgrid.com');
$transport->setPassword('*************');
$swift = Swift_Mailer::newInstance($transport);
// Create a message (subject)
$message = new Swift_Message($subject);
// add SMTPAPI header to the message
$headers = $message->getHeaders();
$headers->addTextHeader('X-SMTPAPI', $hdr->asJSON());
// attach the body of the email
$message->setFrom($from);
$message->setBody($html, 'text/html');
$message->setTo($to);
$message->addPart($text, 'text/plain');
// Send message
$recipients = $swift->send($message, $failures)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment