Skip to content

Instantly share code, notes, and snippets.

@atwellpub
Created April 12, 2016 20:00
Show Gist options
  • Save atwellpub/26fbcbd34cecda23aabb938a03b8afd3 to your computer and use it in GitHub Desktop.
Save atwellpub/26fbcbd34cecda23aabb938a03b8afd3 to your computer and use it in GitHub Desktop.
Example send through Mandrill snippe.
<?php
/**
* Sends email using Inbound Now's mandrill sender
*/
public static function send_email( $send_now = false) {
$settings = Inbound_Mailer_Settings::get_settings();
$mandrill = new Inbound_Mandrill( $settings['api_key'] );
$message = array(
'html' => self::$email['body'],
//'text' => self::get_text_version(),
'subject' => self::$email['subject'],
'from_email' => self::$email['from_email'],
'from_name' => self::$email['from_name'],
'to' => array(
array(
'email' => self::$email['send_address'],
//'name' => 'Recipient Name',
'type' => 'to'
)
),
'headers' => array('Reply-To' => self::$email['reply_email']),
'important' => false,
'track_opens' => true,
'track_clicks' => true,
'auto_text' => true,
'auto_html' => false,
'inline_css' => false,
'url_strip_qs' => false,
'preserve_recipients' => false,
'view_content_link' => true,
'bcc_address' => false,
'tags' => self::$tags[ self::$row->email_id ],
'metadata' => array(
'email_id' => self::$row->email_id,
'lead_id' => self::$row->lead_id,
'variation_id' => self::$row->variation_id,
'nature' => self::$email_settings['email_type']
),
'recipient_metadata' => array(
array(
'rcpt' => self::$email['send_address'],
'values' => array(
'lead_id' => self::$row->lead_id
)
)
),
/*
'attachments' => array(
array(
'type' => 'text/plain',
'name' => 'myfile.txt',
'content' => 'ZXhhbXBsZSBmaWxl'
)
),
'images' => array(
array(
'type' => 'image/png',
'name' => 'IMAGECID',
'content' => 'ZXhhbXBsZSBmaWxl'
)
)
*/
);
$async = false;
$ip_pool = 'Main Pool';
if ( !$send_now ) {
$send_at = gmdate( 'Y-m-d h:i:s \G\M\T' , strtotime( self::$row->datetime ) );
} else {
$send_at = false;
}
/* error_log( print_r( $message , true ) ); */
self::$response = $mandrill->messages->send($message, $async, $ip_pool, $send_at );
do_action( 'inbound_mandrill_send_event' , $message , $send_at );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment