使用PHPMailer格式化Gmail API的MIME邮件时如何发送到BCC地址?
我正在使用
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”地址时,我在发送的邮件标题中看不到“未公开的收件人”,并且邮件未传输到BCC地址. 当我使用gmail web界面发送电子邮件并在那里提供“BCC”地址时,我确实在发送的邮件标题中看到“未公开的收件人”,并且邮件被发送到BCC地址. 有谁知道这个问题的解决方法? 解决方法
PHPMailer将在内部跟踪BCC收件人,如果您要使用PHPMailer发送消息,它将在
SMTP envelope期间指定BCC收件人.
但是,当您从PHPMailer中提取原始消息时,您将丢失PHPMailer正在跟踪的内部收件人列表. raw message不包括BCC信息. To:和Cc:标头将包含相应的收件人,GMAIL API可能使用这些标头来推断预期的收件人. 要添加BCC收件人,您需要使用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(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |