post() публичный Метод

public post ( string $endpointUrl, array $postData = [], array $files = [] ) : stdClass
$endpointUrl string
$postData array
$files array
Результат stdClass
Пример #1
0
 /**
  * @param string|array $view
  * @param array        $data
  * @param \Closure     $callback
  * @param null         $message
  *
  * @return \Bogardo\Mailgun\Http\Response
  */
 public function send($view, array $data, Closure $callback, $message = null)
 {
     $this->message = $message ?: new Message($this->mailgun->MessageBuilder(), $this->config);
     $this->callMessageBuilder($callback, $this->message);
     $this->renderBody($view, $data);
     $message = $this->message->getMessage();
     $files = $this->message->getFiles();
     $domain = $this->config->get('mailgun.domain');
     $response = new Response($this->mailgun->post("{$domain}/messages", $message, $files));
     return $response;
 }
 public function addList()
 {
     # Instantiate the client.
     $mgClient = new Mailgun('YOUR_API_KEY');
     # Issue the call to the client.
     $result = $mgClient->post("lists", array('address' => 'LIST@YOUR_DOMAIN_NAME', 'description' => 'Mailgun Dev List'));
 }
Пример #3
0
 public function setAdressToOkMailGun($recipient)
 {
     $mgClient = new Mailgun(env('Mailgun_Secret_API_Key', false));
     $defaultAddress = env('Mailgun_Forward_Address', false);
     $result = $mgClient->post('routes', ['priority' => 2000, 'expression' => 'match_recipient("' . $recipient . '")', 'action' => ['forward("' . $defaultAddress . '")', 'stop()'], 'description' => 'Ok']);
     return $result->http_response_code . ': ' . $result->http_response_body->message;
 }
 public function listaddmemberAction($listname, $address, $name)
 {
     $logger = $this->container->get('logger');
     $mailgun = new Mailgun($this->private_key, $this->APIURL, "v3", true);
     $listAddress = $listname . $this->GROUPEMAIL;
     $checkresult = $mailgun->get("lists", array('address' => '' . $listAddress));
     $decodedresult = json_decode(json_encode($checkresult), true);
     $count = $decodedresult['http_response_body']['total_count'];
     $logger->info('Testing adding member ' . $address);
     if ($decodedresult['http_response_code'] != 200) {
         $result = $this->listcreateAction($listname, ' the list ' . $listname, $address, $name);
         $logger->info('adding list ' . $address . ' ' . serialize($result));
     }
     $result = $mailgun->post("lists/{$listAddress}/members", array('address' => '' . $address, 'name' => '' . $name, 'subscribed' => true, 'upsert' => true));
     $logger->info('adding member ' . $address . ' ' . serialize($result));
     return $this->JsonResponse($result);
 }
Пример #5
0
 /**
  * @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]);
 }
 /**
  * Add an array of emails to a Mailgun list
  *
  * @since 1.0.0
  *
  * @param string $list_address The address of the list to add addresses to.
  * @param array $array Array of emails to be JSON encoded.
  */
 public function add_array_list_members($list_address, $array)
 {
     if (is_array($array)) {
         $json = json_encode($array);
         try {
             // Instantiate the client.
             $mg_client = new Mailgun(MAILGUN_API_KEY);
             // Issue the call to the client.
             $result = $mg_client->post("lists/{$list_address}/members.json", array('members' => $address, 'upsert' => 'true'));
             return $result;
         } catch (Exception $e) {
             $this->custom_log('The following error occured when trying to add addresses to ' . $list_address . ': ' . $e->getMessage());
         }
     } else {
         $this->custom_log('Bad array input:' . print_r($json));
     }
 }
Пример #7
0
<?php 
require 'mailgun-php/vendor/autoload.php';
use Mailgun\Mailgun;
// mailgun credentials
$mg = new Mailgun("key-a643dfc4abedf6a8ee23c2173b5a2c96");
// $mgValidate = new Mailgun('pub-key-example');
$domain = "thehealthbits.com";
$mailingList = "subscribers@" . $domain;
$secretPassphrase = 'a_secret_passphrase';
$recipientName = $_POST['fields_fname'];
$recipientAddress = $_POST['fields_email'];
# Let's validate the customer's email address, using Mailgun's validation endpoint.
// $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'    => '*****@*****.**',
//                                 'to'      => $recipientAddress,
//                                 'subject' => 'Please Confirm!',
//                                 'html'    => "<html><body>Hello,<br><br>You have requested to be subscribed
//                                               to the mailing list $mailingList. Please <a
//                                               href=\"http://yourdomain.com/subscribe.php?hash=$generatedHash\">
//                                               confirm</a> your subscription.<br><br>Thank you!</body></html>"));
# Finally, let's add the subscriber to a Mailing List, as unsubscribed, so we can track non-conversions.
$mg->post("lists/{$mailingList}/members", array('address' => $recipientAddress, 'name' => $recipientName, 'subscribed' => true, 'upsert' => 'yes'));
// }
header("Location:/subscribe-thank-you/");
die;
Пример #8
0
 function mg_add_subscriber($email_id, $name = NULL)
 {
     $key = get_instance()->config->item('mailgun_key');
     $mg = new Mailgun($key);
     $list_address = get_instance()->config->item('newsletter_address');
     # Issue the call to the client.
     $result = $mg->post("lists/{$list_address}/members", array('address' => $email_id, 'name' => $name, 'subscribed' => 'yes', 'upsert' => 'true'));
 }
Пример #9
0
 /**
  *
  * 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']);
     }
 }
Пример #10
0
 /**
  * Transport mail message with mailgun services
  *
  * @param $to
  * @param $subj
  * @param $body
  * @param $hash
  * @param $intro
  * @param $options
  *
  * @return bool
  */
 public static function transportMailMailgun($to, $subj, $body, $hash, $intro, $options)
 {
     // @TODO make sure that from and reply-to addresses are correctly set in headers
     if (!is_array($to)) {
         $to = explode(',', $to);
     }
     $signature = Util::lavnn('signature', $options, 'team');
     $language = Util::lavnn('language', $options, 'en');
     $sender = Util::lavnn('sender', $options, 0);
     $config = Config::getInstance();
     # Instantiate the client.
     $mgClient = new Mailgun($config->get('mailgun.apiKey'));
     $domain = $config->get('mailgun.domain');
     $msgBuilder = $mgClient->MessageBuilder();
     $from = $config->get('mailgun.from');
     if ($signature != 'team' && $sender > 0) {
         $userModel = new User();
         if ($userModel->load($sender)->isValid()) {
             $from = $userModel->get('fname') . ' ' . $userModel->get('lname') . ' <' . $userModel->get('email') . '>';
         }
     }
     $msgBuilder->setFromAddress($from);
     foreach ($to as $recipient) {
         $msgBuilder->addToRecipient(trim($recipient));
     }
     $msgBuilder->setSubject($subj);
     $msgBuilder->setTextBody(self::prepareTextMail($subj, $body, $hash, $intro, $signature, $language, $sender));
     $msgBuilder->setHtmlBody(self::prepareHtmlMail($subj, $body, $hash, $intro, $signature, $language, $sender));
     $result = $mgClient->post("{$domain}/messages", $msgBuilder->getMessage(), $msgBuilder->getFiles());
     return $result->http_response_code == 200;
 }
Пример #11
0
<?php

use Mail\Mail;
require '../vendor/autoload.php';
$loader = new Twig_Loader_Filesystem('../views/twig');
$twig = new Twig_Environment($loader, array('cache' => false));
$mail = new Mail();
if (isset($_POST['from'])) {
    $mail->writeMail($_POST);
    $mail->sendMail();
}
echo $twig->render("form.twig");
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = new Mailgun('key-3c246e362731a7f0458f67ea00e31479');
# Issue the call to the client.
$result = $mgClient->post("routes", array('priority' => 0, 'expression' => 'match_recipient(".*@sandboxbcb41bc62f6d485e9e43ef8edb592f7b.mailgun.org")', 'action' => array('forward("*****@*****.**")', 'stop()'), 'description' => 'Sample route'));
Пример #12
0
 public function send(MessageViewModel $message)
 {
     $domain = $this->options->getDomain();
     return $this->mg->post("{$domain}/messages", $message->getMessage(), $message->getFiles());
 }