Chris Garson Chris Garson - 25 days ago 13
PHP Question

Can't send BCC emails through Mandrill (via Laravel)

I am unable to send emails to users through the Mandrill plugin in Laravel using BCC. I can send emails "to" the addresses, as follows:

Mail::send('emails.coach_invite', $data, function($message) use ($coach, $emails) {
foreach ($emails as $email) {
$message->to($email);
}

$message->subject($coach->first_name.' '.$coach->last_name.' has invited you to try Nudge!');
});


This works just fine. However, if I try to BCC the same users:

Mail::send('emails.coach_invite', $data, function($message) use ($coach, $emails) {
foreach ($emails as $email) {
$message->bcc($email);
}

$message->subject($coach->first_name.' '.$coach->last_name.' has invited you to try Nudge!');
});


Nothing happens. Mandrill doesn't even acknowledge that the request came in. Any ideas why this isn't working? If it helps, here are my raw email headers:

Message-ID: <688aa904847640c9ff694521ccb85ee5@nudge-api.app>
Date: Thu, 07 Aug 2014 11:15:35 -0400
Subject: Coach McTest would like to be your Coach on Nudge!
From: Nudge Info <info@nudgeyourself.com>
Bcc: Chris Garson <chris@nudgeyourself.com>
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Answer

I can confirm that sending emails to Bcc users doesn't really work as expected in Mandrill.

The easiest way to send what you want (single email to multiple addresses, with each addressee only seeing their own name in the delivery list), is to set the X-MC-PreserveRecipients header to false and then just send the email using the To field rather than Bcc.

This will send the email as if it were sent to each recipient individually, rather than as a group email - nobody will know who else was sent the email.

Here's how to do it in Laravel using your example:

Mail::send('emails.coach_invite', $data, function($message) use ($coach, $emails) {

    foreach ($emails as $email) {
        $message->to($email);
    }

    $message->subject($coach->first_name.' '.$coach->last_name.' has invited you to try Nudge!');

    $headers = $message->getHeaders();
    $headers->addTextHeader('X-MC-PreserveRecipients', 'false');
});

Note that I'm using $message->to() to address the email and then adding the X-MC-PreserveRecipients header which is set to false.

Comments