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' => 'http://api.pepipost.com',
]);

// JSON API - https://docs.pepipost.com/documentation/api-integration/json-api/
$response = $client->request('POST', '/api/web.send.json', [ 

    'json' => [
    'api_key'       =>  'YOUR API KEY', // https://docs.pepipost.com/documentation/faq/will-find-pepipost-smtp-detailsapi-key/
    'recipients'    =>  array('user@example.com'),
    'email_details' => array(
    'content'       =>  'This mail is sent via PHP Guzzle',
    'from'          =>  'info@domain.com',
    '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":""}