-
-
Save fakeheal/41052b2734ae1088de05142391312a54 to your computer and use it in GitHub Desktop.
Get invalid recipient's emails from mailgun
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
php logs.php > logs.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Set your domain and api key | |
function fetch_failed_mails($url = "https://api.mailgun.net/v3/domain.com/events?event=failed&limit=300") { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); | |
curl_setopt($ch, CURLOPT_USERPWD, "your-api-key-here"); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); | |
$ch_output = curl_exec($ch); | |
curl_close($ch); | |
$decoded = (array) json_decode($ch_output); | |
return $decoded; | |
} | |
$decoded = fetch_failed_mails(); | |
$output = $decoded['items']; | |
while(isset($decoded['paging']->next) && !empty($decoded['paging']->next)) { | |
$decoded = fetch_failed_mails($decoded['paging']->next.'?limit=300'); | |
if(isset($decoded['items'])) | |
$output = array_merge($output, $decoded['items']); | |
else | |
break; | |
} | |
foreach($output as $email) { | |
echo $email->recipient."\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment