Official PHP Code library for Pepipost
This SDK contains methods for easily interacting with the Pepipost Email Sending API to send emails in a few seconds.
We are trying to make our libraries community driven and we need your help in building the right things the right way you. Your opinion is very much valued so please share comments, create issues and pull requests.
For a smooth installation process, we have categorized installation process according to OS:
-
- A free account on Pepipost. If you don't have a one, click here to signup and get 30,000 emails free every month.
Setup the PEPIPOST API KEY in the library to start sending emails. For example:
- Copy the API KEY from your Pepipost account by navigating to Settings --> Integrations.
- Edit the sample code and replace
PEPIPOST_API_KEY
which the one you just copied. - Now the library is ready to authenticate with Pepipost servers for sending emails.
Developers already familar with GIT, Composer and some of the other handy tools can just refer the below steps to quick start with the integration.
If you are not sure of how to integrate this library within your environment, then please refer to our detailed installation guide above.
- Check php version using below command. Required PHP >=5.4.0.
php -v
- Verify if the Composer is installed using the below command:
composer --version
- Clone this repository on your machine using below command:
git clone https://github.com/pepipost/pepipost-sdk-php.git testSDK
- Change directory
cd testSDK
- Below will install all the requirement needed to run this library. After installing, a vendor directory will get auto-created
composer install
- Copy the code and paste in test.php from simple-usage.php or sampleExample .
cp simple-usage.md test.php
- Get your API key and Sending Domain from your Pepipost account.
- apikey will be available under Login to Pepipost -> Settings -> Integration
- Sending Domain will be available under Login to Pepiost -> Settings -> Sending Domains
*Note :: Domains showing with Active status on Sending Domain dashboard are only allowed to send any sort of emails.* In case there are no Sending Domain added under your account, then first add the domain, get the DNS (SPF/DKIM) settings done and get it reviewed by our compliance team for approval. Once the domain is approved, it will be in ACTIVE status and will be ready to send any sort of emails.
- Make the required changes in your script test.php (Adding the apikey and Sending Domain is mandatory).
Change your $apiKey = 'api-XX-key-XX-here'
to $apiKey = 'api-key-of-your-pepipost-account';
Similarly, update your Sending Domain from:
$body->from->fromEmail = 'admin@myfirsttest.com';
to $body->from->fromEmail = 'admin@your-active-domain-on-pepipost';
- Update the rest of the email related payload like Recipent email address, content of the email etc. Below is the sample code with details of payload:
<?php
require_once "vendor/autoload.php";
use PepipostLib\Models;
use PepipostLib\Exceptions;
$apiKey = '96c909c62bcc1dfdacef7dfdda34ea8477';
$client = new PepipostLib\PepipostClient($apiKey);
$sendController = $client->getMailSend();
$body = new Models\Send;
$body->from = new Models\From;
$body->from->email = 'hello@your-registered-domain-with-pepipost';
$body->from->name = 'Pepipost';
$body->subject = 'Pepipost Test Mail from PHP SDK';
$body->content = array();
$body->content[0] = new Models\Content;
$body->content[0]->type = Models\TypeEnum::HTML;
$body->content[0]->value = '<html><body>Hello [%NAME%], Email testing is successful. <br> Hope you enjoyed this integration. <br></html>';
$body->personalizations = array();
$body->personalizations[0] = new Models\Personalizations;
$body->personalizations[0]->attributes = PepipostLib\APIHelper::deserialize('{"NAME":"User"}');
$body->personalizations[0]->to = array();
$body->personalizations[0]->to[0] = new Models\EmailStruct;
$body->personalizations[0]->to[0]->name = 'to-address@mydomain.name';
$body->personalizations[0]->to[0]->email = 'my-first-user';
$body->settings = new Models\Settings;
$body->settings->footer = true;
$body->settings->clickTrack = true;
$body->settings->openTrack = true;
$body->settings->unsubscribeTrack = true;
try {
$result = $sendController->createGenerateTheMailSendRequest($body);
var_dump($result);
} catch (PepipostLib\APIException $e) {
echo 'Caught APIException: ', $e->getMessage(), "\n";
}
?>
For more information about the parameters, we would like to recommend our API docs
- Run your script to send your first test email
php test.php
This will give you following output:
{
"data": {
"message_id": "e8820eeb0ee94807f1ce88652b1dd627"
},
"message": "OK",
"status": "success"
}
v5.1.0 has been released! Please see the release notes for details.
All updates to this library are documented in our releases. For any queries and feedbacks, feel free to reach out us at dx@pepipost.com
If you are interested in the future direction of this project, please take a look at our open issues and pull requests. We would love to hear your feedback.
pepipost-php-sdk library is guided and supported by the Pepipost Developer Experience Team. This pepipost-php-sdk library is maintained and funded by Pepipost Ltd. The names and logos for pepipost-php-sdk are trademarks of Pepipost Ltd.
This code library was semi-automatically generated by APIMATIC v2.0 and licensed under The MIT License (MIT).