USING THE EMAILONAPPROVED PLUGIN WITH ANY MULTI-RECORD SECTION - Oct 26th, 2017


Because I didn't want to allow non-members to upload images (or other files) directly to the database, I wanted to send
an email to a person that posted a listing request once it was approved and listed.
That email would ask them to reply to the email with an image attached.

I was at a loss until I got some help from Jeff Shields a long time CMSB user.

Here's how it works:
A person submits an event for listing.
The submission creates an email to the admin with all the information about the event, and a preformatted link that will
create the listing record. (see the recipe: USING AN EMAIL TEMPLATE TO CREATE A NEW ACCOUNT RECORD )
The admin reviews the information, and if it’s appropriate, clicks the link to create a record.
When they save the record (with an 'approved' check box automatically checked) the modified plugin automatically sends
an email to the person who listed the event that they should email an event image to the admin.

Here's the original plugin code:

<?php


addAction('record_postsave', 'emailOnApproved_sendPassword', null, 4);

//
function emailOnApproved_sendPassword($tableName, $isNewRecord, $oldRecord, $recordNum) {
global
$CURRENT_USER, $SETTINGS;
$fieldname = 'approved';

// error checking
if ($tableName != 'accounts') { return; }
if (!
array_key_exists($fieldname, $CURRENT_USER)) {
die(
__FUNCTION__ .": You must create an accounts fields called '$fieldname'!");
}

// send email
$wasChecked = intval(!$oldRecord[$fieldname] && $_REQUEST[$fieldname]);
$wasUnchecked = intval($oldRecord[$fieldname] && !$_REQUEST[$fieldname]);

$message=<<< __TEXT__
Welcome!

Your subscription has been processed successfully and you now have access to the Members Only area of our web site.
Your user name is: {$_REQUEST['username']}
and your temporary password is: {$_REQUEST['password']}
Once you have successfully logged in, you can change your password and update your profile information.


<a href="http://www.your_website_URL.com{$GLOBALS['WEBSITE_LOGIN_LOGIN_FORM_URL']}">Click here to login</a>

Best,

The Subscription Committee
__TEXT__;


$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .="FROM:". $SETTINGS['adminEmail'];

if (
$wasChecked) {
$errors = mail($_REQUEST['email'],"Your membership has been successfully processed!",$message,$headers);
if (
$errors!=1) { die("Mail Error: $php_errormsg"); }
}

}

?>

and here's the code after Jeff's suggestions:
It assumes a multi-record table called: 'your_table_name', a check box field called 'approved', a first name field
called 'first_name', and an email field called 'email'.
note that all references to $CURRENT_USER have been removed since they are related to the website membership plugin.

<?php


addAction('record_postsave', 'emailOnApproved_sendPassword', null, 4);


//
function emailOnApproved_sendPassword($tableName, $isNewRecord, $oldRecord, $recordNum) {
$fieldname = 'approved';

// error checking
if ($tableName != 'your_table_name') { return; }

// send email
$wasChecked = intval(!$oldRecord[$fieldname] && $_REQUEST[$fieldname]);
$wasUnchecked = intval($oldRecord[$fieldname] && !$_REQUEST[$fieldname]);

$message=<<< __TEXT__
Hello {$_REQUEST['first_name']},

Your event has been posted, but a compelling picture would make your listing really stand out.

You can send us an image by replying to this email with your image attached.

Please note, images should be in .jpg format and no larger than 1mb in size.

Best,

The Listing Team
__TEXT__;

$the_from = 'your_from_email@your_site.com';
$the_to = $_REQUEST['email'];
$the_subject = 'Your Subject Line';
$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"); }
}

}

?>






The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service