I’ve been facing an issue when sending emails solely through the BCC field with Mailgun’s PHP API. Emails send correctly when both a primary recipient and a BCC are provided, but attempts to use only a BCC address result in failure—even when an empty string is passed to the primary recipient.
function dispatchEmail($mainRecipient, $emailTitle, $emailContent, $blindList) {
$keySecret = "";
$hostDomain = "";
$session = curl_init();
curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($session, CURLOPT_USERPWD, 'api:' . $keySecret);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($session, CURLOPT_URL, 'https://api.mailgun.net/v3/' . $hostDomain . '/messages');
curl_setopt($session, CURLOPT_POSTFIELDS, array(
'from' => 'Sender Name <[email protected]>',
'to' => $mainRecipient,
'bcc' => $blindList,
'subject' => $emailTitle,
'html' => $emailContent,
'o:tracking' => 'yes'
));
$result = curl_exec($session);
curl_close($session);
return $result;
}
dispatchEmail($mainRecipient, $emailTitle, $emailContent, $blindList);