Readme, cleanup
This commit is contained in:
		
							parent
							
								
									84d3b511a0
								
							
						
					
					
						commit
						516ced28e1
					
				
							
								
								
									
										40
									
								
								README.markdown
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								README.markdown
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,40 @@
 | 
				
			|||||||
 | 
					CodeIgniter-Dynect API
 | 
				
			||||||
 | 
					=========================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Connect to the Dynect API with CodeIgniter (PHP)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Installation
 | 
				
			||||||
 | 
					------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1.  Copy system/application/libraries/Dynect_API.php to your application/libraries folder
 | 
				
			||||||
 | 
					2.  Review the sample code in system/application/controllers/welcome.php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Config
 | 
				
			||||||
 | 
					------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Usage
 | 
				
			||||||
 | 
					------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					First, load the library and instantiate the class.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    $this->load->library('Dynect_API');
 | 
				
			||||||
 | 
					    $dyn = new Dynect_API();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Then, login. Make sure to logout at the end.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    $dyn->login();
 | 
				
			||||||
 | 
					    // do things
 | 
				
			||||||
 | 
					    $dyn->logout();	
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					What you do is up to you. Here's what I've written so far:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    print_r($dyn->get_all_records('foobo.com','test.foobo.com'));
 | 
				
			||||||
 | 
					    print_r($dyn->get_zones());
 | 
				
			||||||
 | 
					    print_r($dyn->create_zone("feebeetest1.com", "admin@feebeetest1.com", 3600));
 | 
				
			||||||
 | 
					    print_r($dyn->publish_zone("feebeetest1.com"));
 | 
				
			||||||
 | 
					    print_r($dyn->delete_zone("feebeetest1.com"));
 | 
				
			||||||
 | 
					    print_r($dyn->get_records('A','foobo.com','test.foobo.com'));
 | 
				
			||||||
 | 
					    print_r($dyn->create_record('A', 'feebeetest1.com', 'test.feebeetest1.com', array('address' => '127.0.0.1')));
 | 
				
			||||||
 | 
					    print_r($dyn->delete_records('A', 'foobo.com', 'test.foobo.com'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1,71 +0,0 @@
 | 
				
			|||||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 | 
					 | 
				
			||||||
 
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
|--------------------------------------------------------------------------
 | 
					 | 
				
			||||||
| POSTMARK API KEY
 | 
					 | 
				
			||||||
|--------------------------------------------------------------------------
 | 
					 | 
				
			||||||
|
 | 
					 | 
				
			||||||
| Enter your Postmark API key here.
 | 
					 | 
				
			||||||
|
 | 
					 | 
				
			||||||
| This key is available by visiting your Postmark Rack, clicking 'Details'
 | 
					 | 
				
			||||||
| next to the desiered server, then clicking 'Settings & API Credentials'
 | 
					 | 
				
			||||||
|
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
$config['api_key'] = '';
 | 
					 | 
				
			||||||
 
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
|--------------------------------------------------------------------------
 | 
					 | 
				
			||||||
| FROM NAME & FROM ADDRESS
 | 
					 | 
				
			||||||
|--------------------------------------------------------------------------
 | 
					 | 
				
			||||||
|
 | 
					 | 
				
			||||||
| These are optional settings
 | 
					 | 
				
			||||||
|
 | 
					 | 
				
			||||||
| If you're going to be using the same Sender Signature for all emails, it
 | 
					 | 
				
			||||||
| might be easier to assign it here, than doing so with each individual
 | 
					 | 
				
			||||||
| email. If you are not using this setting, comment it out.
 | 
					 | 
				
			||||||
|
 | 
					 | 
				
			||||||
| Configure your Sender Signatures at http://postmarkapp.com/signatures
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
$config['from_name'] = 'Will Bradley';
 | 
					 | 
				
			||||||
$config['from_address'] = 'bradley.will@gmail.com';
 | 
					 | 
				
			||||||
 
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
|--------------------------------------------------------------------------
 | 
					 | 
				
			||||||
| VALIDATION
 | 
					 | 
				
			||||||
|--------------------------------------------------------------------------
 | 
					 | 
				
			||||||
|
 | 
					 | 
				
			||||||
| Setting validation to TRUE will require that you pass Postmark valid
 | 
					 | 
				
			||||||
| email addresses for sender and reciever. If these are not valid email
 | 
					 | 
				
			||||||
| addresses, the request to send an email will not be sent to Postmark.
 | 
					 | 
				
			||||||
|
 | 
					 | 
				
			||||||
| This is reccomended on high traffic servers
 | 
					 | 
				
			||||||
|
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
$config['validation'] = TRUE;
 | 
					 | 
				
			||||||
 
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
|--------------------------------------------------------------------------
 | 
					 | 
				
			||||||
| STRIP_HTML
 | 
					 | 
				
			||||||
|--------------------------------------------------------------------------
 | 
					 | 
				
			||||||
|
 | 
					 | 
				
			||||||
| Setting strip_tags to TRUE will strip all HTML tags from _plain_message
 | 
					 | 
				
			||||||
| using PHP's strip_tags() function. It should be noted that the output
 | 
					 | 
				
			||||||
| will probably be far from what you would expect.
 | 
					 | 
				
			||||||
|
 | 
					 | 
				
			||||||
| Experimental Feature
 | 
					 | 
				
			||||||
|
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
$config['strip_html'] = TRUE;
 | 
					 | 
				
			||||||
 
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
|--------------------------------------------------------------------------
 | 
					 | 
				
			||||||
| DEVELOP
 | 
					 | 
				
			||||||
|--------------------------------------------------------------------------
 | 
					 | 
				
			||||||
|
 | 
					 | 
				
			||||||
| Often when implementing your client library or when integrating an
 | 
					 | 
				
			||||||
| existing library into your application you would want to send 'test'
 | 
					 | 
				
			||||||
| emails that don't actually get delivered to the recipient. You just need
 | 
					 | 
				
			||||||
| to know if your data is valid. You can do that by setting this to TRUE
 | 
					 | 
				
			||||||
|
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
$config['develop'] = TRUE;
 | 
					 | 
				
			||||||
@ -1,452 +0,0 @@
 | 
				
			|||||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Postmark Email Library
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Permits email to be sent using Postmarkapp.com's Servers
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @category	Libraries
 | 
					 | 
				
			||||||
 * @author      Based on work by János Rusiczki & Markus Hedlund’s.
 | 
					 | 
				
			||||||
 * @modified    Heavily Modified by Zack Kitzmiller
 | 
					 | 
				
			||||||
 * @link        http://www.github.com/zackkitzmiller/postmark-codeigniter
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class Postmark {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    //private
 | 
					 | 
				
			||||||
    var $CI;
 | 
					 | 
				
			||||||
    var $api_key = '';
 | 
					 | 
				
			||||||
    var $validation = FALSE;
 | 
					 | 
				
			||||||
    var $strip_html = FALSE;
 | 
					 | 
				
			||||||
    var $develop = FALSE;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    var $from_name;
 | 
					 | 
				
			||||||
    var $from_address;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    var $_reply_to_name;
 | 
					 | 
				
			||||||
    var $_reply_to_address;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    var $_to_name;
 | 
					 | 
				
			||||||
    var $_to_address;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    var $_cc_name;
 | 
					 | 
				
			||||||
    var $_cc_address;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    var $_subject;
 | 
					 | 
				
			||||||
    var $_message_plain;
 | 
					 | 
				
			||||||
    var $_message_html;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    var $_tag;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Constructor
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @access	public
 | 
					 | 
				
			||||||
     * @param	array	initialization parameters
 | 
					 | 
				
			||||||
     */	
 | 
					 | 
				
			||||||
    function Postmark($params = array())
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $this->CI =& get_instance();
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        if (count($params) > 0)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            $this->initialize($params);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    	
 | 
					 | 
				
			||||||
    	if ($this->develop == TRUE)
 | 
					 | 
				
			||||||
    	{
 | 
					 | 
				
			||||||
    	   $this->api_key = 'POSTMARK_API_TEST';
 | 
					 | 
				
			||||||
    	}
 | 
					 | 
				
			||||||
    	
 | 
					 | 
				
			||||||
        log_message('debug', 'Postmark Class Initialized');
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// --------------------------------------------------------------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Initialize Preferences
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @access	public
 | 
					 | 
				
			||||||
	 * @param	array	initialization parameters
 | 
					 | 
				
			||||||
	 * @return	void
 | 
					 | 
				
			||||||
	 */	
 | 
					 | 
				
			||||||
    function initialize($params)
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
        $this->clear();
 | 
					 | 
				
			||||||
		if (count($params) > 0)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            foreach ($params as $key => $value)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                if (isset($this->$key))
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    $this->$key = $value;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// --------------------------------------------------------------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Clear the Email Data
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @access	public
 | 
					 | 
				
			||||||
	 * @return	void
 | 
					 | 
				
			||||||
	 */	
 | 
					 | 
				
			||||||
    function clear() {
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
        $this->from_name = '';
 | 
					 | 
				
			||||||
    	$this->from_address = '';
 | 
					 | 
				
			||||||
    	
 | 
					 | 
				
			||||||
    	$this->_to_name = '';
 | 
					 | 
				
			||||||
    	$this->_to_address = '';
 | 
					 | 
				
			||||||
    	
 | 
					 | 
				
			||||||
    	$this->_cc_name = '';
 | 
					 | 
				
			||||||
    	$this->_cc_address = '';
 | 
					 | 
				
			||||||
    	
 | 
					 | 
				
			||||||
    	$this->_subject = '';
 | 
					 | 
				
			||||||
    	$this->_message_plain = '';
 | 
					 | 
				
			||||||
    	$this->_message_html = '';
 | 
					 | 
				
			||||||
    	
 | 
					 | 
				
			||||||
    	$this->_tag = '';	
 | 
					 | 
				
			||||||
    	
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	// --------------------------------------------------------------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Set Email FROM address
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * This could also be set in the config file
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * TODO:
 | 
					 | 
				
			||||||
	 * Validate Email Addresses ala CodeIgniter's Email Class
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @access	public
 | 
					 | 
				
			||||||
	 * @return	void
 | 
					 | 
				
			||||||
	 */	
 | 
					 | 
				
			||||||
	function from($address, $name = null)
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if ( ! $this->validation == TRUE)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
            $this->from_address = $address;
 | 
					 | 
				
			||||||
            $this->from_name = $name;
 | 
					 | 
				
			||||||
		} 
 | 
					 | 
				
			||||||
		else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            if ($this->_validate_email($address))
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                $this->from_address = $address;
 | 
					 | 
				
			||||||
                $this->from_name = $name;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                show_error('You have entered an invalid sender address.');
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	// --------------------------------------------------------------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Set Email TO address
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * TODO:
 | 
					 | 
				
			||||||
	 * Validate Email Addresses ala CodeIgniter's Email Class
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @access	public
 | 
					 | 
				
			||||||
	 * @return	void
 | 
					 | 
				
			||||||
	 */	
 | 
					 | 
				
			||||||
	function to($address, $name = null)
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
	        
 | 
					 | 
				
			||||||
		if ( ! $this->validation == TRUE)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
            $this->_to_address = $address;
 | 
					 | 
				
			||||||
            $this->_to_name = $name;
 | 
					 | 
				
			||||||
		} 
 | 
					 | 
				
			||||||
		else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            if ($this->_validate_email($address))
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                $this->_to_address = $address;
 | 
					 | 
				
			||||||
                $this->_to_name = $name;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                show_error('You have entered an invalid recipient address.');
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	// --------------------------------------------------------------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Set Email ReplyTo address
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * TODO:
 | 
					 | 
				
			||||||
	 * Validate Email Addresses ala CodeIgniter's Email Class
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @access	public
 | 
					 | 
				
			||||||
	 * @return	void
 | 
					 | 
				
			||||||
	 */	
 | 
					 | 
				
			||||||
	function reply_to($address, $name = null)
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
	        
 | 
					 | 
				
			||||||
		if ( ! $this->validation == TRUE)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
            $this->_reply_to_address = $address;
 | 
					 | 
				
			||||||
            $this->_reply_to_name = $name;
 | 
					 | 
				
			||||||
		} 
 | 
					 | 
				
			||||||
		else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            if ($this->_validate_email($address))
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                $this->_reply_to_address = $address;
 | 
					 | 
				
			||||||
                $this->_reply_to_name = $name;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                show_error('You have entered an invalid reply to address.');
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// --------------------------------------------------------------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Set Email CC address
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * TODO:
 | 
					 | 
				
			||||||
	 * Validate Email Addresses ala CodeIgniter's Email Class
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @access	public
 | 
					 | 
				
			||||||
	 * @return	void
 | 
					 | 
				
			||||||
	 */	
 | 
					 | 
				
			||||||
	function cc($address, $name = null)
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
	        
 | 
					 | 
				
			||||||
		if ( ! $this->validation == TRUE)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
            $this->_cc_address = $address;
 | 
					 | 
				
			||||||
            $this->_cc_name = $name;
 | 
					 | 
				
			||||||
		} 
 | 
					 | 
				
			||||||
		else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            if ($this->_validate_email($address))
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                $this->_cc_address = $address;
 | 
					 | 
				
			||||||
                $this->_cc_name = $name;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                show_error('You have entered an invalid recipient address.');
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
	// --------------------------------------------------------------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Set Email Subject
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @access	public
 | 
					 | 
				
			||||||
	 * @return	void
 | 
					 | 
				
			||||||
	 */	
 | 
					 | 
				
			||||||
	function subject($subject)
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		$this->_subject = $subject;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	// --------------------------------------------------------------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Set Tag
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @access	public
 | 
					 | 
				
			||||||
	 * @return	void
 | 
					 | 
				
			||||||
	 */	
 | 
					 | 
				
			||||||
	function tag($tag)
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		$this->_tag = $tag;
 | 
					 | 
				
			||||||
	}	
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	// --------------------------------------------------------------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Set Email Message in Plain Text
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @access	public
 | 
					 | 
				
			||||||
	 * @return	void
 | 
					 | 
				
			||||||
	 */	
 | 
					 | 
				
			||||||
	function message_plain($message)
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		if ( ! $this->strip_html )
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
		  $this->_message_plain = $message;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		else
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
		  $this->_message_plain = $this->_strip_html($message);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}  
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// --------------------------------------------------------------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Set Email Message in HTML
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @access	public
 | 
					 | 
				
			||||||
	 * @return	void
 | 
					 | 
				
			||||||
	 */	
 | 
					 | 
				
			||||||
	function message_html($message)
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		$this->_message_html = $message;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// --------------------------------------------------------------------
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
    * Private Function to prepare and send email
 | 
					 | 
				
			||||||
    */
 | 
					 | 
				
			||||||
	function _prepare_data()
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
        $data = array();
 | 
					 | 
				
			||||||
		$data['Subject'] = $this->_subject;
 | 
					 | 
				
			||||||
        		
 | 
					 | 
				
			||||||
		$data['From'] = is_null($this->from_name) ? $this->from_address : "{$this->from_name} <{$this->from_address}>";
 | 
					 | 
				
			||||||
		$data['To'] = is_null($this->_to_name) ? $this->_to_address : "{$this->_to_name} <{$this->_to_address}>";
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (!is_null($this->_cc_address) && ($this->_cc_address != '')) {
 | 
					 | 
				
			||||||
            $data['Cc'] = is_null($this->_cc_name) ? $this->_cc_address : "{$this->_cc_name} <{$this->_cc_address}>";
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (!is_null($this->_reply_to_address) && ($this->_reply_to_address != '')) {
 | 
					 | 
				
			||||||
            $data['ReplyTo'] = is_null($this->_reply_to_name) ? $this->_reply_to_address : "{$this->_reply_to_name} <{$this->_reply_to_address}>";
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (!is_null($this->_tag) && ($this->_tag != '')) {
 | 
					 | 
				
			||||||
		  $data['tag'] = $this->_tag;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (!is_null($this->_message_html)) {
 | 
					 | 
				
			||||||
			$data['HtmlBody'] = $this->_message_html;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (!is_null($this->_message_plain)) {
 | 
					 | 
				
			||||||
			$data['TextBody'] = $this->_message_plain;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		return $data;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
    function send($from_address = null, $from_name = null, $to_address = null, $to_name = null, $subject = null, $message_plain = null, $message_html = null)
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
        if (!function_exists('curl_init'))
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            if(function_exists('log_message'))
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                log_message('error', 'Postmark - PHP was not built with cURL enabled. Rebuild PHP with --with-curl to use cURL.');            
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            return false;    
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
		if (!is_null($from_address)) $this->from($from_address, $from_name);
 | 
					 | 
				
			||||||
		if (!is_null($to_address)) $this->to($to_address, $to_name);
 | 
					 | 
				
			||||||
		if (!is_null($subject)) $this->subject($subject);
 | 
					 | 
				
			||||||
		if (!is_null($message_plain)) $this->message_plain($message_plain);
 | 
					 | 
				
			||||||
		if (!is_null($message_html)) $this->message_html($message_html);
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
		if (is_null($this->api_key)) {
 | 
					 | 
				
			||||||
			show_error("Postmark API key is not set!");
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (is_null($this->from_address)) {
 | 
					 | 
				
			||||||
			show_error("From address is not set!");
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (is_null($this->_to_address)) {
 | 
					 | 
				
			||||||
			show_error("To address is not set!");
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (is_null($this->_subject)) {
 | 
					 | 
				
			||||||
			show_error("Subject is not set!");
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (is_null($this->_message_plain) && is_null($this->_message_html)) {
 | 
					 | 
				
			||||||
			show_error("Please either set plain message, HTML message or both!");
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
		$encoded_data = json_encode($this->_prepare_data());
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		$headers = array(
 | 
					 | 
				
			||||||
			'Accept: application/json',
 | 
					 | 
				
			||||||
			'Content-Type: application/json',
 | 
					 | 
				
			||||||
			'X-Postmark-Server-Token: ' . $this->api_key
 | 
					 | 
				
			||||||
		);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		$ch = curl_init();
 | 
					 | 
				
			||||||
		curl_setopt($ch, CURLOPT_URL, 'http://api.postmarkapp.com/email');
 | 
					 | 
				
			||||||
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 | 
					 | 
				
			||||||
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
 | 
					 | 
				
			||||||
		curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded_data);
 | 
					 | 
				
			||||||
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		$return = curl_exec($ch);
 | 
					 | 
				
			||||||
		log_message('debug', 'POSTMARK JSON: ' . $encoded_data . "\nHeaders: \n\t" . implode("\n\t", $headers) . "\nReturn:\n$return");
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (curl_error($ch) != '') {
 | 
					 | 
				
			||||||
			show_error(curl_error($ch));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
 | 
					 | 
				
			||||||
		log_message('debug', 'POSTMARK http code:' . $httpCode);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (intval($httpCode / 100) != 2) {
 | 
					 | 
				
			||||||
			$message = json_decode($return)->Message;
 | 
					 | 
				
			||||||
			show_error('Error while mailing. Postmark returned HTTP code ' . $httpCode . ' with message "'.$message.'"');
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	// --------------------------------------------------------------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Email Validation
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @access	public
 | 
					 | 
				
			||||||
	 * @param	string
 | 
					 | 
				
			||||||
	 * @return	bool
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	function _validate_email($address)
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		$addresses = explode(',', $address);
 | 
					 | 
				
			||||||
				
 | 
					 | 
				
			||||||
		foreach($addresses as $k => $v) {
 | 
					 | 
				
			||||||
            if ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", trim($v))) {
 | 
					 | 
				
			||||||
                return FALSE;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
        return TRUE;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// --------------------------------------------------------------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Strip Html
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @access	public
 | 
					 | 
				
			||||||
	 * @param	string
 | 
					 | 
				
			||||||
	 * @return	string
 | 
					 | 
				
			||||||
	 */	
 | 
					 | 
				
			||||||
	function _strip_html($message)
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
        $message =  preg_replace('/\<br(\s*)?\/?\>/i', "\n", $message);
 | 
					 | 
				
			||||||
        return strip_tags($message);
 | 
					 | 
				
			||||||
	}	
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user