Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send mail only to bcc with mailgun php API? [duplicate]

I am trying to send mail only to Bcc but unable to send. Code given below is working fine with To and Bcc but when i try to send only with Bcc it fails. I tried passing empty string with To but didnt work. I am using mailgun php API.

function send_mail($email,$subject,$msg,$bcc)
{
    $api_key="";
    $domain ="";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_USERPWD, 'api:'.$api_key);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v2/'.$domain.'/messages');
    curl_setopt($ch, CURLOPT_POSTFIELDS, array(
    'from' => 'Example <[email protected]>',
    'to' => $email,
    'bcc' => $bcc,
    'subject' => $subject,
    'html' => $msg,
    'o:tracking' => true)); 
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}
send_mail($email, $subject, $msg, $bcc);
like image 498
niteshd22 Avatar asked Feb 13 '15 15:02

niteshd22


People also ask

What is the unique identifier for the only email successfully sent to multiple recipients?

Message-ID is a unique identifier for a digital message, most commonly a globally unique identifier used in email and Usenet newsgroups. Message-IDs are required to have a specific format which is a subset of an email address and be globally unique. No two different messages must ever have the same Message-ID.

How many emails can I send with Mailgun?

5,000 messages/month are included. There is a limit of 300 messages per day on the included sandbox domain. Data retention for Logs and the Events API is 1 day.

Does Mailgun send SMS?

TextMagic, also a Mailgun customer, allows you to send notifications, alerts, reminders, confirmations and SMS marketing campaign messages to your customers, staff members and suppliers. On average, TextMagic customers are sending over 2.5M text messages around the world each month.


1 Answers

You may not send mail only using bcc. There is a trick I use in which I make the from and to the same address (something like [email protected]) and then fill up the bcc slot with whatever I need.

You may send mail using mailing lists that does not require you to expose other email addresses. https://documentation.mailgun.com/en/latest/api-mailinglists.html

like image 130
Nathaniel Johnson Avatar answered Oct 24 '22 15:10

Nathaniel Johnson