mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-22 20:46:03 +03:00
Updated README files and fixed a bug in OptInHandler
This commit is contained in:
parent
143414f174
commit
522f731929
@ -55,8 +55,8 @@ $mg = new Mailgun("key-example");
|
|||||||
$domain = "example.com";
|
$domain = "example.com";
|
||||||
|
|
||||||
# Now, issue a GET against the Logs endpoint.
|
# Now, issue a GET against the Logs endpoint.
|
||||||
$mg->get('{$domain}/log', array('limit' => 'bob@example.com',
|
$mg->get("$domain/log", array('limit' => 25,
|
||||||
'skip' => 'sally@example.com');
|
'skip' => 0);
|
||||||
```
|
```
|
||||||
|
|
||||||
For usage examples on each API endpoint, head over to our official documentation pages.
|
For usage examples on each API endpoint, head over to our official documentation pages.
|
||||||
|
@ -27,7 +27,7 @@ class OptInHandler{
|
|||||||
$concatStrings = $secretAppId . "" . $urlParameters->r;
|
$concatStrings = $secretAppId . "" . $urlParameters->r;
|
||||||
|
|
||||||
if($urlParameters->s == hash('md5', $concatStrings)){
|
if($urlParameters->s == hash('md5', $concatStrings)){
|
||||||
$returnArray = array('recipientAddress' => $urlParameters->r, 'mailingList' => $mailingList);
|
$returnArray = array('recipientAddress' => $urlParameters->r, 'mailingList' => $urlParameters->l);
|
||||||
return $returnArray;
|
return $returnArray;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -9,9 +9,9 @@ There is currently one utility provided.
|
|||||||
|
|
||||||
OptInHandler: Provides methods for authenticating an OptInRequest.
|
OptInHandler: Provides methods for authenticating an OptInRequest.
|
||||||
|
|
||||||
The typical flow for using this utility would be as follow:
|
The typical flow for using this utility would be as follows:
|
||||||
(Recipient Requests Subscribe) -> [Generate Opt In Link] -> [Email Recipient Opt In Link]
|
**Recipient Requests Subscribe** -> [Validate Recipient Address] -> [Generate Opt In Link] -> [Email Recipient Opt In Link]
|
||||||
(Recipient Clicks Opt In Link) -> [Validate Opt In Link] -> [Subscribe User] -> [Send final confirmation]
|
**Recipient Clicks Opt In Link** -> [Validate Opt In Link] -> [Subscribe User] -> [Send final confirmation]
|
||||||
|
|
||||||
The above flow is modeled below.
|
The above flow is modeled below.
|
||||||
|
|
||||||
@ -20,32 +20,39 @@ Usage - Opt-In Handler (Recipient Requests Subscribe)
|
|||||||
Here's how to use Opt-In Handler to validate Opt-In requests.
|
Here's how to use Opt-In Handler to validate Opt-In requests.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
# First, instantiate the SDK with your API credentials and domain.
|
# First, instantiate the SDK with your API credentials, domain, and required parameters for example.
|
||||||
$mg = new Mailgun("key-example");
|
$mg = new Mailgun('key-example');
|
||||||
$domain = "example.com";
|
$mgValidate = new Mailgun('pub-key-example');
|
||||||
|
|
||||||
|
$domain = 'example.com';
|
||||||
|
$mailingList = 'youlist@example.com';
|
||||||
|
$secretPassphrase = 'a_secret_passphrase';
|
||||||
|
$recipientAddress = 'recipient@example.com';
|
||||||
|
|
||||||
|
# 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.
|
# Next, instantiate an OptInHandler object from the SDK.
|
||||||
$optInHandler = $mg->OptInHandler();
|
$optInHandler = $mg->OptInHandler();
|
||||||
|
|
||||||
# Next, define necessary variables and generate a hash.
|
# Next, generate a hash.
|
||||||
$mailingList = 'youlist@example.com';
|
|
||||||
$secretPassphrase = 'a_secret_passphrase';
|
|
||||||
$recipientAddress = 'recipient@example.com'
|
|
||||||
$generatedHash = $optInHandler->generateHash($mailingList, $secretPassphrase, $recipientAddress);
|
$generatedHash = $optInHandler->generateHash($mailingList, $secretPassphrase, $recipientAddress);
|
||||||
|
|
||||||
# Now, let's send a confirmation to the recipient with our link.
|
# Now, let's send a confirmation to the recipient with our link.
|
||||||
$mg->sendMessage($domain, array('from' => 'bob@example.com',
|
$mg->sendMessage($domain, array('from' => 'bob@example.com',
|
||||||
'to' => 'sally@example.com',
|
'to' => $recipientAddress,
|
||||||
'subject' => 'Please Confirm!',
|
'subject' => 'Please Confirm!',
|
||||||
'html' => '<html><body>Hello,<br><br>You have requested to be subscribed
|
'html' => "<html><body>Hello,<br><br>You have requested to be subscribed
|
||||||
to the mailing list {$mailingList}. Please <a
|
to the mailing list $mailingList. Please <a
|
||||||
href="http://yourdomain.com/subscribe.php?hash=$generatedHash">confirm
|
href=\"http://yourdomain.com/subscribe.php?hash=$generatedHash\">
|
||||||
</a> your subscription.<br><br>Thank you!</body></html>'));
|
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.
|
# Finally, let's add the subscriber to a Mailing List, as unsubscribed, so we can track non-conversions.
|
||||||
$mg->post('{$domain}/lists/{$mailingList}', array('address' => $recipientAddress,
|
$mg->post("lists/$mailingList/members", array('address' => $recipientAddress,
|
||||||
'subscribed' => 'no',
|
'subscribed' => 'no',
|
||||||
'upsert' => 'yes');
|
'upsert' => 'yes'));
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Usage - Opt-In Handler (Recipient Clicks Opt In Link)
|
Usage - Opt-In Handler (Recipient Clicks Opt In Link)
|
||||||
@ -54,8 +61,8 @@ Here's how to use Opt-In Handler to validate an Opt-In Hash.
|
|||||||
|
|
||||||
```php
|
```php
|
||||||
# First, instantiate the SDK with your API credentials and domain.
|
# First, instantiate the SDK with your API credentials and domain.
|
||||||
$mg = new Mailgun("key-example");
|
$mg = new Mailgun('key-example');
|
||||||
$domain = "example.com";
|
$domain = 'example.com';
|
||||||
|
|
||||||
# Next, instantiate an OptInHandler object from the SDK.
|
# Next, instantiate an OptInHandler object from the SDK.
|
||||||
$optInHandler = $mg->OptInHandler();
|
$optInHandler = $mg->OptInHandler();
|
||||||
@ -72,16 +79,16 @@ if($hashValidation){
|
|||||||
$validatedList = $hashValidation['mailingList'];
|
$validatedList = $hashValidation['mailingList'];
|
||||||
$validatedRecipient = $hashValidation['recipientAddress'];
|
$validatedRecipient = $hashValidation['recipientAddress'];
|
||||||
|
|
||||||
$mg->put('{$domain}/lists/{$validatedList}/{$validatedRecipient}',
|
$mg->put("lists/$validatedList/members/$validatedRecipient",
|
||||||
array('address' => $recipientAddress,
|
array('address' => $validatedRecipient,
|
||||||
'subscribed' => 'yes');
|
'subscribed' => 'yes'));
|
||||||
|
|
||||||
$mg->sendMessage($domain, array('from' => 'bob@example.com',
|
$mg->sendMessage($domain, array('from' => 'bob@example.com',
|
||||||
'to' => 'sally@example.com',
|
'to' => $validatedRecipient,
|
||||||
'subject' => 'Please Confirm!',
|
'subject' => 'Confirmation Received!',
|
||||||
'html' => '<html><body>Hello,<br><br>We\'ve successfully subscribed
|
'html' => "<html><body>Hello,<br><br>We've successfully subscribed
|
||||||
you to the list, {$mailingList}!<br><br>Thank you!
|
you to the list, $validatedList!<br><br>Thank you!
|
||||||
</body></html>'));
|
</body></html>"));
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user