我正在使用PHPMailer构建电子邮件消息。 我只使用PHPMailer进行MIME消息格式化,而不是发送。
然后在将其传递给Gmail API处理之前,我从PHPMailer对象中提取原始消息。
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
$mail->IsHTML(true);
//Disable SMTP debugging
// 0 = off (for production use)
$mail->SMTPDebug = 0;
//Set who the message is to be sent from
$mail->setFrom("fromaddress@domain.com", "From Name");
//Set an alternative reply-to address
$mail->addReplyTo("replyaddress@domain.com", "Reply Name");
//Set to address
$mail->addAddress("address@domain.com", "Some Name");
//Set CC address
$mail->addCC("ccaddress@ccdomain.com", "Some CC Name");
//Set BCC address
$mail->addBCC("bccaddress@ccdomain.com", "Some BCC Name");
//Set the subject line
$mail->Subject = "Test message";
//Set the body
$mail->Body = file_get_contents("/messagestore/some.html");
//Attach a file
$mail->addAttachment("/messagestore/some.pdf","some.pdf","base64","application/pdf");
//generate mime message
$mail->preSend();
//get the mime text
$mime = $mail->getSentMIMEMessage();
//do the google API dance
$newMailMessage = new Google_Service_Gmail_Message();
$data = base64_encode($mime);
$data = str_replace(array('+','/','='),array('-','_',''),$data); // url safe
$newMailMessage->setRaw($data);
$gmailService = new Google_Service_Gmail($google_client);
$gmailService->users_messages->send('me', $newMailMessage);
根据PHPMailer文档,CC和BCC只能在Win32环境下发送。
然而,我的MIME格式的邮件通过Gmail API成功传输到“TO”和“CC”地址,但无法传输到“BCC”地址。
总之,当我使用这段代码发送电子邮件并提供“BCC”地址给Gmail API时,在发送的邮件头中我没有看到“未公开收件人”,且该消息未传输到BCC地址。
当我使用Gmail网页界面发送邮件并在那里提供“BCC”地址时,我看到了发送消息头中的“未公开收件人”,并且该邮件已经传递到BCC地址。
有人知道解决这个问题的方法吗?