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

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

如何在 google 邮件中给予多个抄送 api

$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=数组 ( [0] => xyzw@gmail.com )

因为 header for Cc 确实允许多封电子邮件,您可以将其作为用逗号分隔的字符串放在那里:

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

这应该允许您将其发送到多个抄送。

或者只是替换你的行:

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

为了

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