title: Cannot get the body of email with Gmail PHP API
body: <p>I'm having trouble with the Gmail PHP API.</p>
  
  <p>I want to retrieve the body content of emails, but I can retrieve it only for emails which have attachments! My question is why?</p>
  
  <p>Here's my code so far:</p>
  
  <pre><code>// Authentication things above...
  $client = getClient();
  $gmail = new Google_Service_Gmail($client);    
  $list = $gmail-&gt;users_messages-&gt;listUsersMessages('me', ['maxResults' =&gt; 1000]);
  
  while ($list-&gt;getMessages() != null) {   
      foreach ($list-&gt;getMessages() as $mlist) {               
          $message_id = $mlist-&gt;id;   
          $optParamsGet2['format'] = 'full';
          $single_message = $gmail-&gt;users_messages-&gt;get('me', $message_id, $optParamsGet2);
  
          $threadId = $single_message-&gt;getThreadId();
          $payload = $single_message-&gt;getPayload();
          $headers = $payload-&gt;getHeaders();
          $parts = $payload-&gt;getParts();
          //print_r($parts); PRINTS SOMETHING ONLY IF I HAVE ATTACHMENTS...
          $body = $parts[0]['body'];
          $rawData = $body-&gt;data;
          $sanitizedData = strtr($rawData,'-_', '+/');
          $decodedMessage = base64_decode($sanitizedData); //should display my body content
      }
  
      if ($list-&gt;getNextPageToken() != null) {
          $pageToken = $list-&gt;getNextPageToken();
          $list = $gmail-&gt;users_messages-&gt;listUsersMessages('me', ['pageToken' =&gt; $pageToken, 'maxResults' =&gt; 1000]);
      } else {
          break;
      }
  }
  </code></pre>
  
  <p>The second option to retrieve content that I know is by using the snippet located in the <strong>Headers</strong> part, but it only retrieves the 50 first characters or so, which isn't very useful.</p>