/**
* @param Request $request
*
* @throws \Mailgun\Messages\Exceptions\MissingRequiredMIMEParameters
*/
public function getConfirm(Request $request)
{
$mg = new Mailgun(config('services.mailgun.secret'));
$domain = config('services.mailgun.domain');
$optInHandler = $mg->OptInHandler();
$inboundHash = $request->get('hash');
$secretPassphrase = env('APP_KEY');
$hashValidation = $optInHandler->validateHash($secretPassphrase, $inboundHash);
if ($hashValidation) {
$validatedList = $hashValidation['mailingList'];
$validatedRecipient = $hashValidation['recipientAddress'];
$body = "<html><body>Olá,<br><br>Adicionamos seu email na nossa lista, {$validatedList}!<br><br>Obrigado!</body></html>";
$mg->put("lists/{$validatedList}/members/{$validatedRecipient}", array('address' => $validatedRecipient, 'subscribed' => 'yes'));
$mg->sendMessage($domain, array('from' => config('services.mailgun.contact'), 'to' => $validatedRecipient, 'subject' => 'Confirmado!', 'html' => $body));
return Response::make($body);
}
return Response::make("Não foi possível confirmar sua inscrição, tente novamente mais tarde.");
}