Skip to content

This component interfaces a Laravel app with YMLP/Your Mailing List Provider's API.

License

Notifications You must be signed in to change notification settings

nexana/Laravel-YMLP-Plugin

 
 

Repository files navigation

CakePHP YMLP Component

YMLP, or Your Mailing List Provider, is a email newsletter and marketing service with free and paid accounts, and a well written API.

This component interfaces a CakePHP app with YMLP's API.

You will need a free or paid account at YMLP, along with your username and API key (found at ymlp.com under "Configuration", "API"). Make sure to enable API access on YMLP's API page!

Compatibility:

Tested with CakePHP 2.3.x. Requires PHP 5 with cURL support.

Installation:

Using Composer/Packagist:

In your project composer.json file:

{
	"require": {
		"chronon/ymlp": "*"
	}
}

Using git:

git clone [email protected]:chronon/CakePHP-YmlpComponent-Plugin.git APP/Plugin/Ymlp  

Configuration:

All configuration is in APP/Config/bootstrap.php.

Required: Load the plugin:

CakePlugin::load('Ymlp');

or

CakePlugin::loadAll();

Required: Set your YMLP API key and username.

Configure::write('Ymlp.settings', array(
	'Key' => '1234567890ABCDEFG',
	'Username' => 'yourusername',
));

Required: Set your YMLP field mapping, which is your local field => YMLPField.

Configure::write('Ymlp.fieldMap', array(
	'email' => 'Email',
));

Usage:

Add the component to your controller:

public $components = array('Ymlp.Ymlp');

Example: if you have a subscriber form with a field named email, $this->request->data would look something like this:

['Subscriber'] => array(
	'email' => '[email protected]'
)

To add this email address to YMLP using the component:

$result = $this->Ymlp->command('Contacts.Add', $this->request->data['Subscriber']);

The $result would be the response from YMLP's Contacts.Add() method. See the YMLP docs for all available API commands.

The available methods of this component are:

utility($method, $data = array())

/**
 * A utility method to send anything to the YMLP API
 *
 * @param string $method The YMLP API method call
 * @param array  $data Data to pass to the YMLP method
 * @return string
 * @access public
 */
 
command($method, $data)

/**
 * The primary method to format data, post it to the YMLP API, and then format
 * the returned result.
 *
 * @param string $method The YMLP API method call
 * @param array  $data Data to pass to the YMLP method
 * @return string
 * @access public
 */

Example usage of the utility method to view a list of configured YMLP fields. If you created a form at YMLP to collect name, email address, and mailing address, you need to match your app's fields with YMLP fields. The YMLP API Fields.GetList() method can give you what you need.

Create a temporary method in your controller and use the component's utility method:

public function utility() {
	$result = $this->Ymlp->utility('Fields.GetList');
	debug($result);
	exit;
}

Visit /utility and you should see a list of YMLP configured fields with field id, which you can use to map to your app fields with the Ymlp.fieldMap configuration array.

Configure::write('Ymlp.fieldMap', array(
	'email' => 'Email',
	'first_name' => 1,
	'last_name' => 2,
	'address' => 3,
	'city' => 4,
	'state' => 5,
	'zip' => 6,
));

About

This component interfaces a Laravel app with YMLP/Your Mailing List Provider's API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published