phpgoogle-email-settings-api

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

$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 )


Solution

  • As header for Cc does allow multiple emails you can just put it in there as string separated by commas:

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

    This should allow you to send it to multiple Cc's.

    Or just replace your line:

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

    for

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