<?php

// hook into wordpresses mail function. This only works if permalinks are set up. 
function saveContact() {
    
    
// the kohana controler that will deal with $_POST
    
$url 'http://' $_SERVER['SERVER_NAME'] .  '/example';
        
    
// we'll let kohana know where this is comming from
    
$_POST['origin'] = $_SERVER['REQUEST_URI'];
    
    
// cURL yourself
    // send it kohana to deal with
    
$ch curl_init();
    
curl_setopt$chCURLOPT_URL$url );
    
curl_setopt$chCURLOPT_FOLLOWLOCATION);
    
curl_setopt$chCURLOPT_POST);
    
curl_setopt$chCURLOPT_POSTFIELDS$_POST );
    
curl_setopt$chCURLOPT_RETURNTRANSFERtrue); 
    
$result curl_exec$ch );
    
curl_close$ch );
}

add_action'wp_mail''saveContact' );


// this is what our kohana controller would like 
// from the root dir application/controllers/example.php

defined('SYSPATH') OR die('No direct access allowed.');
/**
 * Hijacks wordpress from a wp_mail() call and stores the data.
 */
class Example_Controller extends Controller {

    public function 
index() {
        
$this->auto_render false;
        
        
// clean it
        
$data $this->input->post();

        
// we'll use the current page to determine contact type
        
$uri =  $_POST['origin'];
        
$uri ltrim$uri'/' );
        
$path explode'/'$uri );

        
// we can use the path to put into a specific table and use a different model to work with the data
        
$data['path'] = $path;

        
// for this example I'll just send it all to the contact model

        // insert it
        
$contact = new Contact_Model;
        
$contact->insert$data );

    }
}

?>