How to send mail only to bcc with mailgun php API?

与世无争的帅哥 提交于 2019-12-04 10:42:06

问题


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 <examle@examle.com>',
    '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);

回答1:


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 info@mydomain.com) 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/user_manual.html#mailing-lists



来源:https://stackoverflow.com/questions/28503099/how-to-send-mail-only-to-bcc-with-mailgun-php-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!