Laravel 4 & Mandrill JSON response
I started sending emails via Laravel (4.2) and the Mandrill built-in driver these days, but I need to catch Mandrill's answer somehow.
Here's the code I'm using to send the message:
Mail::queue('emails.customerspromo', array('messaggio'=>$content, 'disclaimer'=>$disclaimer, 'user_email'=>$to, 'user_id'=>$uid), function($message) use ($sender, $to, $subject) {
$message->from('my@address.it', $sender);
$message->to($to);
$message->subject($subject);
$message->setCharset('UTF-8');
$message->getHeaders()->addTextHeader('X-MC-GoogleAnalytics', 'www.my-site.it');
$message->getHeaders()->addTextHeader('X-MC-GoogleAnalyticsCampaign', 'my-campaign');
});
I need to intercept Mandrill JSON response like:
[
{
"email": "destination@address.com",
"status": "sent",
"_id": "80e1ca49d3ed4cbb9d9a3d932c0a14f8",
"reject_reason": null
}
]
How can I do this using Laravel's built-in drivers for Mandrill?
I could use Mail :: send instead of the Mail :: queue if necessary to interpret the response in real time.
+3
source to share
1 answer
Place a variable in front of your post function like this:
$ response = Mail :: queue ('emails.customerspromo', array ('messaggio' => $ content, 'disclaimer' => $ disclaimer, 'user_email' => $ to, 'user_id' => $ uid), function ($ message) use ($ sender, $ to, $ subject) { $ message-> from (' my@address.it ', $ sender); $ message-> to ($ to); $ message-> subject ($ subject); $ message-> setCharset ('UTF-8'); $ message-> getHeaders () -> addTextHeader ('X-MC-GoogleAnalytics', 'www.my-site.it'); $ message-> getHeaders () -> addTextHeader ('X-MC-GoogleAnalyticsCampaign', 'my-campaign'); });
It will still work, but now you can see the response from the mandrill.
0
source to share