本文整理汇总了PHP中Mailgun\Mailgun::post方法的典型用法代码示例。如果您正苦于以下问题:PHP Mailgun::post方法的具体用法?PHP Mailgun::post怎么用?PHP Mailgun::post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mailgun\Mailgun
的用法示例。
在下文中一共展示了Mailgun::post方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
/**
* @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;
}
示例2: addList
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: setAdressToOkMailGun
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;
}
示例4: listaddmemberAction
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: postNews
/**
* @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 = 'novidades@phpmga.net';
$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]);
}
示例6: add_array_list_members
/**
* 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: Mailgun
<?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' => 'bob@example.com',
// '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: Mailgun
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: subscribe
/**
*
* 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: transportMailMailgun
/**
* 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: array
<?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("nino@skvorc.org")', 'stop()'), 'description' => 'Sample route'));
示例12: send
public function send(MessageViewModel $message)
{
$domain = $this->options->getDomain();
return $this->mg->post("{$domain}/messages", $message->getMessage(), $message->getFiles());
}