Skip to content

Instantly share code, notes, and snippets.

@pierot
Created March 27, 2014 13:40
Show Gist options
  • Select an option

  • Save pierot/9807777 to your computer and use it in GitHub Desktop.

Select an option

Save pierot/9807777 to your computer and use it in GitHub Desktop.
private static function init() {
self::$mandrill = new Mandrill(Config::get('app.mandrill.api_key'));
}
private static function send($from_email, $from_name, $recipients, $subject, $html, $text = null, $dynamic_values = array()) {
self::init();
$data = array(
"html" => $html,
"text" => $text,
"subject" => $subject,
"from_email" => $from_email,
"from_name" => $from_name,
"to" => $recipients,
"track_opens" => true,
"track_clicks" => true,
"merge_vars" => $dynamic_values,
"preserve_recipients" => false
);
$message = new Mandrill_Messages(self::$mandrill);
$response = $message->send($data, false);
self::parse_response($response);
return $response;
}
private static function parse_response($response) {
if(count($response) == 1) {
if(is_array($response[0])) {
if(array_key_exists('status', $response[0])) {
$status = $response[0]['status'];
if($status === 'rejected' || $status === 'invalid') {
\Log::warning("Sending email to " . $response[0]['email'] . " returned status: $status");
}
}
}
}
}
public static function order($order) {
$view = View::make('emails.order', array('order' => $order, 'config' => $order->config));
$recipients = array(
array(
'email' => Config::get('app.mail_to'),
'name' => 'NAAM'
),
);
$response = self::send(
'SENDER EMAIL,
"SENDER NAME",
$recipients,
'SUBJECT',
$view->render()
);
Log::info('[ORDER] ' . print_r($response, true));
return;
// Mail::send(
// 'emails.order',
// array('order' => $order),
// function($message) {
// $message->from(Mailer::$from, 'SOM Order Bot');
//
// $message->to(Mailer::$to)->subject('SOM - Order');
//
// Log::info('[ORDER] ' . $message->toString());
// }
// );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment