简体   繁体   English

如何使用php和google gmail api向多个电子邮件Cc ID发送电子邮件?

[英]How can i send email to multiple email Cc ID's using php and google gmail api?

how to give multiple Cc in google mail api 如何在google mail api中提供多个Cc

$service = new Google_Service_Gmail($client);

         $user = 'me';
         $strSubject = "Faculty status on the track";
         $strRawMessage = "From:<abcd@xyz.center>\r\n";
         $strRawMessage .= "To:" . $studentemail_id . "\r\n";
         $strRawMessage .= "Cc:" .  $coauthordata  . "\r\n";
         $strRawMessage .= 'Subject: =?utf-8?B?' . base64_encode($strSubject) . "?=\r\n";
         $strRawMessage .= "MIME-Version: 1.0\r\n";
         $strRawMessage .= "Content-Type: text/html; charset=utf-8\r\n";
         $strRawMessage .= 'Content-Transfer-Encoding: quoted-printable' . "\r\n\r\n";
         $strRawMessage .= "Name";
         //print_r($strRawMessage);
         //The message needs to be encoded in Base64URL
         $mime = rtrim(strtr(base64_encode($strRawMessage), '+/', '-_'), '=');
        //print_r($mime);
         $msg = new Google_Service_Gmail_Message();
         $msg->setRaw($mime);
      $result=$service->users_messages->send("me", $msg);
`

$coauthordata= Array ( [0] => xyzw@gmail.com ) $ coauthordata = Array([0] => xyzw@gmail.com)

As header for Cc does allow multiple emails you can just put it in there as string separated by commas: 由于Cc的标题允许多个电子邮件,您可以将其放在那里作为以逗号分隔的字符串:

$coauthordata = implode(",",$coauthordata);

This should allow you to send it to multiple Cc's. 这应该允许您将其发送到多个Cc。

Or just replace your line: 或者只是替换你的行:

$strRawMessage .= "Cc:" .  $coauthordata  . "\r\n";

for 对于

$strRawMessage .= "Cc:" .  implode(",",$coauthordata)  . "\r\n";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM