Skip to content

justin-lau/PHPPremailer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHPPremailer - PHP wrapper classes for Premailer API

PHPPremailer is a simple object oriented library that wraps up the API calls to and respond from the Premailer API 0.1. It follows the original API naming as closely as possible and it should be easy to adapt.

Change Log

0.1.1 (2013-01-25)

  • Added CA Cert Suppport

0.1.0 (2013-01-25)

  • Initial commit.

Requirements

Examples

Use a URL as the source

<?php

use PHPPremailer\PremailerClient;

// pass a class constant to define source type
$client = new PremailerClient(PremailerClient::SOURCE_TYPE_URL, 'https://dialect.ca/premailer-tests/base.html');

// or use a literal string
$client = new PremailerClient('url', 'https://dialect.ca/premailer-tests/base.html');

// fluent method call
$response = $client->send()->get_response();

// get html result
$html_result = $response->get_html();

// get plain text result
$text_result = $response->get_text();

Exception

The follow code generates exception due to no URL or HTML is set:

$client = new PremailerClient();

$response = $client->send(); // generates PHPPremailer\PremailerException !

cURL SSL Connection

Although the Premailer API do not support secure connection, both the processed HTML and plain text are stored on Amazon S3 storage service that offer HTTPS.

If you encountered an PHPPremailer\PremailerException with the following message, it means your cURL library wasn't able to find a valid CA Certificate to verify the HTTPS connection:

cURL Error[60]: SSL certificate problem, verify that the CA cert is OK.

According to cURL's documentation, you can either disabled the verification, or let cURL be aware of a CA Certificate that can verify the connection. PHPPremailer is flexible and let you do either.

Disabling the verification makes cURL vulnerable to Man-in-the-middle attacks, but for trivial or testing purpose you can do so:

// pass a class constant
$html_result = $response->get_html(PremailerClient::SSL_NOT_VERIFY);
// or
$html_result = $response->get_html('not verify');

To use a CA Certificate Bundle, just place the pem file at the root folder of the library and name it cacert.pem. The file can be created in many way, and the easiest one among them is to download one from cURL.

Testing

PHPPremailer has a 100% coverage test class included. In order to run the test, you must have [PHPUnit](phpunit --stderr --bootstrap tests/bootstrap.php tests/tests.php) installed.

Running Test

cd tests
phpunit PremailerTest

About

PHP wrapper classes for accessing Premailer API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages