Send email using Gmail API / Google Mail API in PHP
How to make your app use Gmail API to send its email and thus benefit from DKIM authentication
You first need to have your email on your domains managed by gmail: Google for Business.
That means you can already login in gmail on the web with yourname@yourdomain.com
The official documentation can be found there (please be signed in google with your account while accessing).
Basic documentation :
https://developers.google.com/gmail/api/
More documentation related specifically to have your app send mails on behalf of a user :
https://developers.google.com/appengine/docs/php/mail/
Overview
(i) Enable API for your a user
(2) Get the authentication key
(3) Download the client library to save on your server
(4) Write code
https://developers.google.com/gmail/api/
There are two ways to use the Gmail API, one is with a web-server and redirection to google authentication page to click a button to accept, then redirected back to your app with credentials, stored in php session. This is not the way I am looking for.
The second way is "offline" authentication as google labels it. It is with pre-shared authentication keys.
https://developers.google.com/api-client-library/php/guide/aaa_oauth2_service
The sample code provided by google in PHP is there: \google-api-php-client\examples\service-account.php
Write Code
set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/google-api-php-client/src');
(under development..)
Troubleshooting
Fix Error refreshing the OAuth2 token { “error” : “invalid_grant” }
Another website post about this topic http://www.daimto.com/google_service_account_php
Another interesting example : https://productforums.google.com/forum/#!topic/apps/yTiv0EuBKN4