<?php
/*
Plugin Name: Email On Approved
Description: Email the user an image request once they are approved
Version: 1.00
Requires at least: 2.04
*/
// UPDATE THESE VALUES
// DON'T UPDATE ANYTHING BELOW THIS LINE
  
addAction('record_postsave',  'emailOnApproved_sendPassword', null, 4);
//
function emailOnApproved_sendPassword($tableName, $isNewRecord, $oldRecord, $recordNum) {
  $fieldname = 'approved';
  // error checking
    if ($tableName != 'jazz_around_town') { return; } 
  // send email
  $wasChecked   = intval(!$oldRecord[$fieldname] && $_REQUEST[$fieldname]);
  $wasUnchecked = intval($oldRecord[$fieldname]  && !$_REQUEST[$fieldname]);

$message=<<< __TEXT__
	Hello {$_REQUEST['contact_first_name']},<br /><br />
  
Your event has been posted in our 'Jazz Around Town listings'.<br><br>
<font color='red'>AN EXCITING PICTURE WOULD REALLY MAKE YOUR LISTING STAND OUT.</font><br> <br>

You can send us your image by replying to this email with your image attached.<br /> 
<br /> 
Please note, images should be in .jpg format and no larger than 1mb in size.<br /><br />  
  
Best, <br /><br />
    
The Jazz on J Street Team  
__TEXT__;


$the_from = 'joe@jazzonjstreet.com';
$the_to = $_REQUEST['email'];
$the_subject = 'Your Event Has Been Listed On Our Jazz Around Town page';
$headers  = 'MIME-Version: 1.0' . "\r\n";  
$headers .= 'Content-type: text/html; charset=uft-8' . "\r\n";  
$headers .="From:". $the_from; 
  
   if ($wasChecked) { 
    $errors = mail($the_to,$the_subject,$message,$headers);      if ($errors!=1) { die("Mail Error: $php_errormsg"); } 
  } 
 
} 
 
?>