发布于2021-04-13 23:14 阅读(374) 评论(0) 点赞(20) 收藏(4)
我正在使用PHPMailer构建电子邮件。我仅将PHPMailer用于MIME消息格式,而不发送。
然后,我从PHPMailer对象提取原始消息,然后将其传递给Gmail API进行处理。
//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”地址。
总之,当我用发送电子邮件的代码,我提供了一个“密件抄送”地址Gmail的API,我没有看到在发送的邮件标题“未公开的收件人”,消息不发送到BCC地址。
当我使用gmail Web界面发送电子邮件并在其中提供“密件抄送”地址时,在发送的邮件标头中确实看到了“未公开的收件人”,并且邮件已传输到密件抄送地址。
有人知道此问题的解决方法吗?
PHPMailer会在内部跟踪BCC收件人,如果您要使用PHPMailer发送邮件,它将在SMTP信封中指定BCC收件人。
但是,当您从PHPMailer提取原始消息时,您将丢失PHPMailer跟踪的内部收件人列表。该原始消息不包括BCC信息。在To:
和Cc:
标题将包括相应的接收者和GMAIL API可能使用这些标题来推断预期的收件人。
要添加密件抄送收件人,您需要在发送邮件之前使用GMAIL API添加这些收件人。
您未提供您的GMAIL API代码,但它可能遵循以下概述:
$message = new Message();
# construct message using raw data from PHPMailer
$message->setSubjectBody(...);
$message->setTextBody(...);
$message->setHtmlBody(...);
# *** add the BCC recipients here ***
$message->addBcc("secret.recipient@google.com");
# send the message
$message->send();
作者:黑洞官方问答小能手
链接:http://www.phpheidong.com/blog/article/39599/8b3b1f1a3c261bdd3b97/
来源:php黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 php黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-4
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!