<?php
/*
* Plugin Name: Email
* Plugin URI: http://www.bluu.co.nz
* Description: The Universial Plugin for Sending Email for Contact Forms etc..
* Author: Wade Wildbore
* Version: 1.0
* Author URI: http://www.bluu.co.nz
*/
$plugin->add_admin('email_admin.php');
//$plugin->add_action('footer','bluu-interactive', 'tracking');
function captcha()
{
global $error, $filter, $plugin, $email;
if($plugin->get_setting('email', 'recaptcha'))
{
// Require the ReCaptcha Lib
require_once('recaptchalib.php');
// Echo out the captcha
echo recaptcha_get_html($plugin->get_setting('email', 'recaptcha_public_key'));
}
}
function email()
{
global $error, $filter, $plugin, $email;
// Make sure form has been posted
if(isset($_POST['send']))
{
// Check if ReCaptcha has been enabled
if($plugin->get_setting('email', 'recaptcha'))
{
// Require the ReCaptcha Lib
require_once('recaptchalib.php');
// check captcha
$resp = recaptcha_check_answer($plugin->get_setting('email', 'recaptcha_private_key'), $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
// Check if the captcha is valid
if(!$resp->is_valid)
{
// fail
return array('error' => 'Incorrect Captcha', 'data' => $_POST);
}
}
$data = array();
// remove any unwanted posts from being added to the data array
$remove = array('send', 'submit', 'recaptcha_challenge_field', 'recaptcha_response_field');
// loop the $_post array - clean up the keys and values
foreach($_POST as $key => $value)
{
if(!in_array($key, $remove))
{
$data[$filter->add_filter('clean_input', $key)] = $filter->add_filter('clean_input', $value);
}
}
// set some server variables
$data['ip'] = $_SERVER['REMOTE_ADDR'];
$data['useragent'] = $_SERVER['HTTP_USER_AGENT'];
$data['servername'] = $_SERVER['SERVER_NAME'];
$data['time'] = date("F j, Y, g:i a");
// Explode the variables
$vars = explode('%', $plugin->get_setting('email', 'body'));
// lets generate the body, and add in the variables
foreach($vars as $key => $value)
{
if(array_key_exists($value, $data))
{
$body .= $data[$value];
}
else
{
$body .= $value;
}
}
// send the email
if($email->sendemail($plugin->get_setting('email', 'mailto'), $plugin->get_setting('email', 'subject'), $body, $plugin->get_setting('email', 'from')))
{
// success
return array('error' => '0');
}
else
{
// fail
return array('error' => 'A error occured while trying to send the quote.', 'data' => $_POST);
}
}
}
?>