/** * Parses an array of email addresses into two lists: parsed addresses and unparsable portions. * The parsed addresses are a list of addresses that are syntactically valid (and optionally * have DNS and ESP specific grammar checks). * The unparsable list is a list of characters sequences that the parser was not able to * understand. These often align with invalid email addresses, but not always. * * @param array|string $addresses * @param bool $syntaxOnly * * @return mixed */ public function parse($addresses, $syntaxOnly = false) { if (is_array($addresses)) { $addresses = implode(',', $addresses); } $syntaxOnly = $syntaxOnly ? 'true' : 'false'; return $this->mailgun->get('address/parse', ['addresses' => $addresses, 'syntax_only' => $syntaxOnly])->http_response_body; }
/** * Show mailgun status * * @return Response */ public function __invoke() { $mg = new Mailgun(env('MAILGUN_API_KEY')); $domain = env('MAILGUN_DOMAIN'); //TODO better error handling if mailgun API is not accessible $logs = $mg->get("{$domain}/log", array('limit' => 16, 'skip' => 0))->http_response_body->items; $domainResponse = $mg->get("domains/{$domain}"); $domain = $domainResponse->http_response_body->domain; $responseCode = $domainResponse->http_response_code; return view('admin.mailgun.index', compact('logs', 'domain', 'responseCode')); }
public function sendVerificationEmail($where, $what) { # First, instantiate the SDK with your API credentials and define your domain. $msg = new Mailgun(Config::get('mailgun/secret')); $domain = Config::get('info/domain'); # Now, compose and send your message. $msg->sendMessage($domain, array('from' => Config::get('mailgun/from_email'), 'to' => $where, 'subject' => "Your BernBuds email validation code is: {$what}", 'text' => "Your BernBuds email validation code is: {$what}")); $result = $msg->get("{$domain}/log", array('limit' => 1, 'skip' => 0)); $httpResponseCode = $result->http_response_code; $httpResponseBody = $result->http_response_body; return $httpResponseBody; }
public function validateMailgun($attribute, $value, $parameters) { $mgClient = new Mailgun($value); try { $result = $mgClient->get("domains"); } catch (\Mailgun\Connection\Exceptions\InvalidCredentials $e) { return false; } catch (GenericHTTPError $e) { return false; } return true; }
/** * @param int $id * @return CampaignStats */ public function find($id) { $mg = new Mailgun($this->key); $result = $mg->get($this->domain . '/campaigns/' . $id); $stats = $result->http_response_body; $data['clicked'] = $stats->clicked_count; $data['opened'] = $stats->opened_count; $data['submitted'] = $stats->submitted_count; $data['unsubscribed'] = $stats->unsubscribed_count; $data['bounced'] = $stats->bounced_count; $data['delivered'] = $stats->delivered_count; $data['complained'] = $stats->complained_count; $data['dropped'] = $stats->dropped_count; return new CampaignStats($data); }
public function listremovememberAction($listname, $address) { $mailgun = new Mailgun($this->private_key, $this->APIURL, "v3", true); $listAddress = $listname . $this->GROUPEMAIL; $listMember = '' . $address; $checkresult = $mailgun->get("lists", array('address' => '' . $listAddress)); $decodedresult = json_decode(json_encode($checkresult), true); $count = $decodedresult['http_response_body']['total_count']; if ($count == 0) { $result = $this->listcreateAction($listname, ' the list ' . $listname, $address, ' '); if ($result['http_response_code'] != 200) { return $this->JsonResponse($result); } } $checkadress = $mailgun->get("lists/{$listAddress}/members", array('address' => '' . $address)); $decodedresult = json_decode(json_encode($checkadress), true); $count = $decodedresult['http_response_body']['total_count']; if ($count > 0) { $result = $mailgun->delete("lists/{$listAddress}/members/{$listMember}"); } else { $result = $this->listcreateAction($listname, 'new list ' . $listname, $address, ' '); } return $this->JsonResponse($result); }
/** * @param array $searchParams * @param int $limit * @param int $offset * @return Collection */ public function search($searchParams, $limit = 0, $offset = 0) { $mg = new Mailgun($this->key); $apiParams['event'] = $searchParams['event']; if (isset($searchParams['recipient']) && $searchParams['recipient']) { $apiParams['recipient'] = $searchParams['recipient']; } if ($limit > 0) { $apiParams['limit'] = $limit; } if ($limit > 0) { $apiParams['page'] = $offset > 0 ? (int) ($offset / $limit) : 1; } $result = $mg->get($this->domain . '/campaigns/' . $searchParams['id'] . '/events', $apiParams); $final = []; foreach ($result->http_response_body as $event) { $recordArray = (array) $event; $final[] = $this->factory->create($recordArray); } return Collection::make($final); }
/** * @param Request $request * * @throws \Mailgun\Messages\Exceptions\MissingRequiredMIMEParameters */ public function postNews(Request $request) { $mg = new Mailgun(config('services.mailgun.secret')); $mgValidate = new Mailgun(config('services.mailgun.public')); $domain = config('services.mailgun.domain'); $mailingList = '*****@*****.**'; $secretPassphrase = env('APP_KEY'); $recipientAddress = $request->get('email'); $result = $mgValidate->get('address/validate', array('address' => $recipientAddress)); if ($result->http_response_body->is_valid == true) { # Next, instantiate an OptInHandler object from the SDK. $optInHandler = $mg->OptInHandler(); # Next, generate a hash. $generatedHash = $optInHandler->generateHash($mailingList, $secretPassphrase, $recipientAddress); # Now, let's send a confirmation to the recipient with our link. $mg->sendMessage($domain, array('from' => config('services.mailgun.contact'), 'to' => $recipientAddress, 'subject' => 'Por favor confirme sua inscrição!', 'html' => "<html><body>Olá,<br><br>Você solicitou a inclusão de seu email em nossa lista\n {$mailingList}. Por favor <a\n href=\"http://{$domain}/email/confirm?hash={$generatedHash}\">\n confirme</a> sua inscrição.<br><br>Obrigado!</body></html>")); # Finally, let's add the subscriber to a Mailing List, as unsubscribed, so we can track non-conversions. if ($mg->post("lists/{$mailingList}/members", array('address' => $recipientAddress, 'subscribed' => 'no', 'upsert' => 'yes'))) { return Response::make(['success' => true]); } } return Response::make(['success' => false]); }
} $final = array(); $g = 0; for ($i = 0; $i < sizeof($emails); $i++) { if (!isset($final[$g])) { $final += array($g => ""); } if (strlen($final[$g] . $emails[$i] . ",") < 6000) { $final[$g] .= $emails[$i] . ","; } else { substr($final[$g], 0, -1); $g++; } } foreach ($final as $value) { $email_result = $mgClient->get("address/parse", array('addresses' => $value, 'syntax_only' => 'false')); foreach ($email_result->http_response_body->unparseable as $value) { $unparseable_address = $mgClient->get("address/validate", array('address' => $value)); $didyoumean = $unparseable_address->http_response_body->did_you_mean; if (!empty($didyoumean)) { if ($conn->query("UPDATE emails SET email='{$didyoumean}' WHERE email='{$value}'") === TRUE) { echo "Updated: {$value} to {$didyoumean} <br>"; } else { echo "Error updating record: " . $conn->error . "<br>"; } } else { if ($conn->query("DELETE FROM emails WHERE email='{$value}' ") === TRUE) { echo "Deleted: {$value} <br>"; } else { echo "Error deleting record: " . $conn->error . "<br>"; }
/** * Check a Mailgun list for an email address * * @since 1.0.0 * * @param string $list_address The full address list to query. * @param string $address The email address to look for in $list_address. * * @return boolean */ public function check_list_for_member($list_address, $address) { try { // Instantiate the client. $mg_client = new Mailgun(MAILGUN_API_KEY); // Issue the call to the client. $result = $mg_client->get("lists/{$list_address}/members/{$address}", array()); $this->custom_log('check_list_for_member(): ' . $list_address . ' | ' . $address); return true; } catch (Exception $e) { $this->custom_log('Address ' . $address . ' does not exist in list ' . $list_address); return false; } }
<?php require 'autoload.php'; use Mailgun\Mailgun; $mgClient = new Mailgun('key-8bb667ef4a8fc33ed0b3ff93f666ba28'); $domain = 'service.tboopkjj88.com'; $result = $mgClient->get("{$domain}/stats/total", array('event' => array('accepted', 'delivered', 'failed'), 'duration' => '1m')); //print_r($result); print_r("------------><br/>"); $statu = 500; $tempArr; foreach ($result as $key => $value) { if ($key == "http_response_body") { $tempArr = $value; } else { if ($value == 200) { $statu = 200; print_r("<br/>Get data success!<br/>"); } } // print_r("<br/>---------><br/>"); // print_r($value); // print_r("<br>----------><br/>"); } if ($statu == 200) { foreach ($tempArr as $key => $value) { if ($key == "stats") { print_r($value[0]); } } } else {
function mg_get_subscriber($email) { $key = get_instance()->config->item('mailgun_key'); $mg = new Mailgun($key); $list_address = get_instance()->config->item('newsletter_address'); $res = $mg->get("lists/{$list_address}/members/{$email}"); }
/** * * Perform the subscription * */ private function subscribe() { // First, instantiate the SDK with the API credentials, domain, and required parameters. $mg = new Mailgun($this->privateKey); $mgValidate = new Mailgun($this->publicKey); // Let's validate the customer's email address, using Mailgun's validation endpoint. $result = $mgValidate->get('address/validate', array('address' => $this->recipientAddress)); if ($result->http_response_body->is_valid == true) { // Now, let's send a confirmation to the recipient with our link. $mg->sendMessage($this->domain, ['from' => $this->mailingList, 'to' => $this->recipientAddress, 'subject' => 'Thank You!', 'html' => "<html><body>Hello,<br><br>Thank you for subscribing to the " . $this->mailingList . " mailing list. We will let you know about any updates.</body></html>"]); // Finally, let's add the subscriber to a Mailing List. $mg->post("lists/" . $this->mailingList . "/members", ['address' => $this->recipientAddress, 'subscribed' => 'yes', 'upsert' => 'yes']); } }
$response['log'].='|error: invalid email address: '.$sanitiedEmailString.'|'; } */ //$returnEmail=$_POST['returnEmail']; //$contactFirstName=filter_var($_POST['contactFirstName'], FILTER_SANITIZE_STRING); //echo '$contactFirstName='.$contactFirstName; //echo '$contactFirstName:'.$contactFirstName; $from = 'Moodoo Reminder Service <*****@*****.**>'; $to = 'Moodoo Contact Officer <*****@*****.**>'; $subject = 'Reminder - update your Mood'; //$message=$_POST['contactMessage'];//filter_var($_POST['contactMessage'], FILTER_SANITIZE_STRING); $html = '<html><head/><body><p>Hello John! Moodoo has successfully sent a cron message. Time is:' . date('Y-m-d') . '</p></body></html>'; //$text='Test text from script'; # Make the call to the client. $result = $mgClient->sendMessage("{$domain}", array('from' => $from, 'to' => $to, 'subject' => $subject, 'html' => $html)); $result = $mgClient->get("{$domain}/log", array('limit' => 25, 'skip' => 0)); $httpResponseCode = $result->http_response_code; $httpResponseBody = $result->http_response_body; # Iterate through the results and echo the message IDs. $logItems = $result->http_response_body->items; foreach ($logItems as $logItem) { $response['log'] .= "|" . $logItem->message_id . "|"; } function generateOutput() { global $response; //generate json formatted response for client-side javascript use $response['log'] .= 'encoding json|'; $print = json_encode($response); echo $print; }
public function getDomainsFromMailgun($mailgunKey) { $client = new Client(); $mailgunClient = new Mailgun($mailgunKey, $client); return $mailgunClient->get('domains', ['limit' => 100, 'skip' => 0]); }
/** * Checks if an email can be delivered to certain mailbox * * @author salvipascual * @param String $to, email address of the receiver * @param String $subject, subject of the email * @param String $body, body of the email in HTML * @return String delivability status: ok, hard-bounce, soft-bounce, spam, no-reply, loop, unknown * */ public function deliveryStatus($to) { // block people following the example email if ($to == "*****@*****.**") { return 'hard-bounce'; } // check for valid domain $mgClient = new Mailgun("pubkey-5ogiflzbnjrljiky49qxsiozqef5jxp7"); $result = $mgClient->get("address/validate", array('address' => $to)); if (!$result->http_response_body->is_valid) { return 'hard-bounce'; } // block intents to email the deamons if (stripos($to, "mailer-daemon@") !== false || stripos($to, "communicationservice.nl") !== false) { return 'hard-bounce'; } // block no reply emails if (stripos($to, "not-reply") !== false || stripos($to, "notreply") !== false || stripos($to, "no-reply") !== false || stripos($to, "noreply") !== false || stripos($to, "no-responder") !== false || stripos($to, "noresponder") !== false) { return 'no-reply'; } // block emails from apretaste to apretaste $connection = new Connection(); $mailboxes = $connection->deepQuery("SELECT email FROM jumper"); foreach ($mailboxes as $m) { if ($to == $m->email) { return 'loop'; } } // return ok return 'ok'; }