PHP Gmail API - Send draft

Viewed 342

How may I send a draft with GMAIL API and OAuth2.0 via PHP?

In the official docs there is no reference on how to achieve this with PHP.

Based on the Java example, I tried:

$drafts = array();

try {
    $draftsResponse = $service->users_drafts->listUsersDrafts('me');
    if ($draftsResponse->getDrafts()) {
        $drafts = array_merge($drafts, $draftsResponse->getDrafts());
    }
} 

catch (Exception $e) {
    echo 'An error occurred: ' . $e->getMessage();
}

var_dump($drafts);

foreach ($drafts as $draft) {
    echo 'Draft with ID: ' . $draft->getId() . '<br/>';
    $abc = $service->users_drafts->send('me',$draft->getId());
    var_dump($abc);
}

But of course I am doing something wrong, because it is not working. The first var_dump() returns all drafts. But nothing else happens after that.

Can you please help me?

1 Answers
Related