title: Gmail API with PHP mailer can't send multiple attachments
body: <p>I am using PHPmailer with Gmail API to send out mail. This process has worked very well for me for sending just standard emails, however, I want to also have the ability to send out an email with attachments using the Gmail API. When I tried using <code>$mail-&gt;addAttachment($urlString, $name);</code> Gmail would come back with the error <code>Request Entity Too Large Error 413</code> (The size of the attachments never goes above 20MB so it should be well within the 35MB limits of Gmail API).</p>
  
  <p>After some searching, I found out it was because I wasn't using "/Upload URI" for sending large Gmail Attachments (Anything above 5mb and below 35mb). Problem is, I am not very knowledgeable on how to work the Gmail API and only got what I have now from basically copying code from somewhere else and slightly modifying it for my uses and as such, I have no idea how to change the URI like that.</p>
  
  <p>Here is what I have so far, that works with standard emails:</p>
  
  <pre><code>function($agent, $assistantName='', $assistantEmail='', $subject, $body, $attachments=''){
  
  $key = realpath(dirname(__FILE__).'/Services/Google/Gmail.json');
  
          $useremail = 'myuseremail@example.com';
      $toAddress = $agent-&gt;email;
      $agentFirst = $agent-&gt;first_name;
  
  
      $client = new Google_Client();
      putenv('GOOGLE_APPLICATION_CREDENTIALS='.$key);
      $client-&gt;useApplicationDefaultCredentials();
      $user_to_impersonate = $useremail;
      $client-&gt;setSubject($user_to_impersonate);
      $client-&gt;addScope('https://www.googleapis.com/auth/gmail.compose');
      if ($client-&gt;isAccessTokenExpired()) {
        $client-&gt;refreshTokenWithAssertion();
      }
  
          //prepare the mail with PHPMailer
          $mail = new PHPMailer();
          $mail-&gt;CharSet = "UTF-8";
          $mail-&gt;Encoding = "base64";
          $subject = $subject;
          $msg = $body;
          $from = $useremail;
          $fname = "My Name";
          $mail-&gt;From = $from;
          $mail-&gt;FromName = $fname;
          $mail-&gt;AddAddress($toAddress, $agentFirst);
          $mail-&gt;AddCC($assistantEmail, $assistantName);
          $mail-&gt;AddReplyTo($from,$fname);
          if ($attachments != '') {
            foreach ($attachments as $name =&gt; $urlString) {
              $mail-&gt;addAttachment($urlString, $name);
            }
          }
          $mail-&gt;Subject = $subject;
          $mail-&gt;Body = $msg;
          $mail-&gt;IsHTML(true);
          $mail-&gt;preSend();
          $mime = $mail-&gt;getSentMIMEMessage();
          $m = new Google_Service_Gmail_Message();
          $data = base64_encode($mime);
          $data = str_replace(array('+','/','='),array('-','_',''),$data); // url safe
          $m-&gt;setRaw($data);
          $service = new Google_Service_Gmail($client);
          $email = $service-&gt;users_messages-&gt;send($useremail, $m);
          return json_encode($email);
  
  }
  </code></pre>
  
  <p>I don't really know where to go from here, so any help would be appreciated.</p>