PHP cURL for Pepipost

Send Pepipost Transactional Emails via PHP cURL


<?php

/*
* Pepipost Email newsletters
* Send Pepipost Emails Via PHP cURL by Using Pepipost JSON API URL
* API KEY  - https://docs.pepipost.com/documentation/faq/will-find-pepipost-smtp-detailsapi-key/
*/

// Email Data's
$data = array(
    'api_key'        =>  'YOUR API KEY',
    'recipients'    =>  array('user@example.com'),
    'email_details' => array(
        'content'       =>  'This mail is sent via PHP cURL',
        'from'          =>  'info@domain.com',
        'subject'       =>  'Pepipost Test Email',
        'fromname'      =>  'Hello World',    
    )
);

// Print Output in JSON Format
$data_string = json_encode($data);

// Pepipost JSON API URL
$url = "http://api.pepipost.com/api/web.send.json";

//Curl Headers
$headers = array
(
     'Content-Type: application/json'
);  

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);                        
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 7); //Timeout after 7 seconds
    curl_setopt($ch, CURLOPT_HEADER ,0);  // DO NOT RETURN HTTP HEADERS
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers );
   
// Variable for Print the Result
$result = curl_exec($ch);
curl_close ($ch);

// Show result on JSON Format - if you don't want this just add // infront of the echo
echo $result . "\n";

?>
  • Send Emails to Multiple Contacts
'recipients'    =>  array('user1@exampl.com','user2@example.com'),