Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中使用gmail API检查gmail_地址_Php_Gmail_Gmail Api - Fatal编程技术网

如何在php中使用gmail API检查gmail_地址

如何在php中使用gmail API检查gmail_地址,php,gmail,gmail-api,Php,Gmail,Gmail Api,我正在php应用程序中使用gmail api。当我使用发件人电子邮件发送邮件时,它会返回无效的电子邮件。我有一个表sender\u email:在这个表中我登记了所有的gmail地址 我需要检查电子邮件是否有效::如果无效,请更新表sender\u email,查找gmail地址,然后它会找到另一个有效的gmail地址。这是一个持续的过程 以下是使用gmail api检查电子邮件的代码: public static function check_gmail_authentication($fro

我正在php应用程序中使用gmail api。当我使用发件人电子邮件发送邮件时,它会返回
无效的电子邮件
。我有一个表
sender\u email
:在这个表中我登记了所有的gmail地址

我需要检查电子邮件是否有效::如果无效,请更新表
sender\u email
,查找gmail地址,然后它会找到另一个有效的gmail地址。这是一个持续的过程

以下是使用gmail api检查电子邮件的代码:

public static function check_gmail_authentication($from_email, $auth_token){
    while (true)
    {
        try
        {
            $result = GmailSendMessage::re_check_gmail_authentication($from_email, $auth_token);
            if($result == null){
                DB::table('sender_email')->where('email', $from_email)->update(['status' => 'invalid']);
                $sender_email = SenderEmail::where('status','=', 'public')->where('api_type', 'google')->first();
                $from_email = $sender_email->auth_token;
                $auth_token = $sender_email->email;

                //again try
                $result = GmailSendMessage::check_gmail_authentication($from_email, $auth_token);
            }
            break;
        }
        catch(Exception $e)
        {
            print_r($e->getMessage() . ' - failed. Retrying...');
            continue;
        }
    }
}
并在同一控制器中重新检查该方法::

public static function re_check_gmail_authentication($from_email, $auth_token){

    //Google client
    $client = new Google_Client();
    $client->setAuthConfigFile(public_path() . '/apis/api_for_sender_email.json');
    $client->setLoginHint($from_email);
    $client->setAccessType('offline');
    $json_token = $auth_token;

    try {
        $client->setAccessToken($json_token);
        // If access token is not valid use refresh token
        if ($client->isAccessTokenExpired()) {
            $refresh_token = $client->getRefreshToken();
            $client->refreshToken($refresh_token);
        }
        return $from_email;
    } catch (\Exception $e) {
        return false;
    }
}
参数
$from_email=gmail地址
$auth_token=access token

问题::我的代码返回
NULL

我想要什么

  • 我需要一封有效的电子邮件
  • 我需要更新
    发件人\u eamil
    表中的无效电子邮件
  • 请帮助我如何使用
    while
    循环获取有效电子邮件。提前谢谢