我正在尝试仅将邮件发送到密件抄送但无法发送。下面给出的代码适用于 To 和 Bcc,但是当我尝试仅使用 Bcc 发送时,它会失败。我尝试用 To 传递空字符串,但没有用。我正在使用 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);