My question is about implementing white list gong'n through PHP Quickstart

25
February 11, 2019, at 12:00 PM

I want to use PHP QuickStart with Gmail API to implement whitelist or blacklist functions. If the sender is on the blacklist, it will be automatically spam, or only Gmail registered with the service can send letters to each other. How can we achieve this? Thank you.

I've implemented the reply email.

<?php 
require_once __DIR__.'/vendor/autoload.php'; 
session_start(); 
 
$client = new Google_Client(); 
$client->setAuthConfigFile('client_secrets.json'); 
$client->setAccessType("offline"); 
$client->setRedirectUri('https://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php'); 
$client->addScope(Google_Service_Gmail::MAIL_GOOGLE_COM); 
 
if (! isset($_GET['code'])) { 
  $auth_url = $client->createAuthUrl(); 
  header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL)); 
} else { 
  $client->authenticate($_GET['code']); 
  $_SESSION['access_token'] = $client->getAccessToken(); 
  $redirect_uri = 'https://' . $_SERVER['HTTP_HOST'] . '/'; 
  header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL)); 
} 
 
  if ($client->getAccessToken()) { 
 
            $_SESSION['access_token'] = $client->getAccessToken(); 
 
            // Prepare the message in message/rfc822 
           if (isset($_SESSION['gmail_access_token']) &amp;&amp; !empty($_SESSION['gmail_access_token']) ) { 
   
    $client->setAccessToken($_SESSION['gmail_access_token']); 
    $objGMail = new Google_Service_Gmail($client); 
   
    $strSubject = 'this is test email message' . date('M d, Y h:i:s A'); 
   
    $strRawMessage = "From: My Mail <myemail@gmail.com>\r\n"; 
    $strRawMessage .= "To: My Mail <noreply@gmail.com>\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 .= "this is a test !\r\n"; 
   
    //Users.messages->send - Requires -> Prepare the message in message/rfc822 
    try { 
        // The message needs to be encoded in Base64URL 
        $mime = rtrim(strtr(base64_encode($strRawMessage), '+/', '-_'), '='); 
        $msg = new Google_Service_Gmail_Message(); 
        $msg->setRaw($mime); 
   
        //The special value **me** can be used to indicate the authenticated user. 
        $objSentMsg = $objGMail->users_messages->send("me", $msg); 
   
        print('Message sent object'); 
        print($objSentMsg); 
   
    } catch (Exception $e) { 
        print($e->getMessage()); 
        unset($_SESSION['gmail_access_token']); 
    } 
} 
else { 
    // Failed Authentication 
    if (isset($_REQUEST['error'])) { 
        //header('Location: ./index.php?error_code=1'); 
        echo "error auth"; 
    } 
    else{ 
        // Redirects to google for User Authentication 
        $authUrl = $client->createAuthUrl(); 
        header("Location: $authUrl"); 
    } 
}

If there is an implementation, please let me know. thank you.

READ ALSO
WooCommerce wc_logout_url not working when using redirect url

WooCommerce wc_logout_url not working when using redirect url

I am trying to create a custom logout url using WooCommerce, the below works:

47
Automating the numbers of tags in Array of PHP

Automating the numbers of tags in Array of PHP

Each tag word has a number value at the endLike this:

14
What are the image encryption techniques in PHP other than base64? [on hold]

What are the image encryption techniques in PHP other than base64? [on hold]

I want some other techniques to be used to encrypt those images and also how to decrypt and display it on other page

49
How to get resource id on connection establish in ratchet

How to get resource id on connection establish in ratchet

I am using ratchet chat library to create a real-time chat application in PHP CodeIgniterI want to implement one to one chat for which I want to send msg to a particular resource id

12