Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/SendyPHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ class SendyPHP
protected $installation_url;
protected $api_key;
protected $list_id;
protected $verify_ssl = 1;
protected $ca_file;

public function __construct(array $config)
{
//error checking
$list_id = @$config['list_id'];
$installation_url = @$config['installation_url'];
$api_key = @$config['api_key'];
$verify_ssl = @$config['verify_ssl'];
$ca_file = @$config['ca_file'];

if (!isset($list_id)) {
throw new \Exception("Required config parameter [list_id] is not set", 1);
Expand All @@ -33,6 +37,12 @@ public function __construct(array $config)
$this->list_id = $list_id;
$this->installation_url = $installation_url;
$this->api_key = $api_key;

if(isset($verify_ssl))
$this->verify_ssl = $verify_ssl;

if(isset($ca_file))
$this->ca_file = $ca_file;
}

public function setListId($list_id)
Expand Down Expand Up @@ -200,10 +210,15 @@ private function buildAndSend($type, array $values)

$ch = curl_init($this->installation_url .'/'. $type);

// Settings to disable SSL verification for testing (leave commented for production use)
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
// curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
if( ! empty($this->ca_file)) {
curl_setopt($ch,CURLOPT_CAINFO,$this->ca_file);
}

if( ! $this->verify_ssl) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
}

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
Expand Down