Send Transactional Emails using Pepipost and Guzzle, PHP HTTP Client
- Install PHP Guzzle via Composer
composer require guzzlehttp/guzzle
- Send Email Using Pepipost JSON API & PHP Guzzle - POST Method
- index.php
<?php
// Load the Guzzle library.
require_once( dirname(__FILE__) . '/vendor/autoload.php' );
use GuzzleHttp\Client;
$client = new Client([
// Base URI for Pepipost
'base_uri' => 'https://api.pepipost.com',
]);
$response = $client->request('POST', '/api/web.send.json', [
'json' => [
'api_key' => 'YOUR API KEY',
'recipients' => array('[email protected]'),
'email_details' => array(
'content' => 'This mail is sent via PHP Guzzle',
'from' => '[email protected]',
'subject' => 'Pepipost Test Email',
'fromname' => 'Hello World',
)
],
'verify' => false,
]);
$data = $response->getBody();
$data = json_decode($data);
// Print result in array
//print_r($data);
$data= json_encode($data);
// print JSON result
echo $data;
?>
- Output
{"message":"SUCCESS","errorcode":"0","errormessage":""}