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

时间:2019-04-08 09:00:39

标签: php google-email-settings-api

如何在Google Mail 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 )

1 个答案:

答案 0 :(得分:0)

由于Cc标头确实允许多封电子邮件,您可以将其以逗号分隔的形式放在其中:

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

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

或者只是替换您的行:

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

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