我在php应用程序中使用gmail api。当我使用sender_email发送邮件时,它会返回invalid email
。我有一个表sender_email
:在此表中我列出了所有gmail地址。
我需要检查电子邮件是否有效::如果无效,则更新表sender_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 address
和$auth_token = access token
。
问题 ::我的代码返回NULL
我想要什么 ::
sender_eamil
表格请帮助我如何使用while
循环获取有效的电子邮件。谢谢你提前。