Hi Kdub718,
Here's a recipe from my CMSB Cookbook
thecmsbcookbook.com that explains how to use it and a link to the revised plugin.
Hope it helps.
Jerry Kornbluth
IMPLEMENTING THE (CORRECTED) EMAILONAPPROVED PLUGIN WITH THE WEBSITE MEMBERSHIP PLUGIN (ENCRYPTED PASSWORDS)When a prospective member filled out the membership application, I wanted their application to be approved manually. I wanted an e-mail to be sent stating that their application had been received and that as soon as it was processed they would get a second “welcome” e-mail with their username and a temporary password.
NOTE: IMPLEMENTING THE CHANGES OUTLINED IN THIS RECIPE WILL ALLOW THIS PLUGIN TO WORK CORRECTLY WITH ENCRYPTED PASSWORDS (CMSB VERSION 2.08+ AND THE WEBSITE MEMBERSHIP PLUGIN V1.05+).
NOTE: Thanks to Steve from MustBeOnLine.com for discovering a coding error in the zipped plugin (now fixed). He discovered that there was a double $mail= in the line of code:
$errors = $errors=mail($_REQUEST['email'],"Your membership has been approve!",$message,$headers);,
It should be:
$errors = mail($_REQUEST['email'],"Your membership has been approve!",$message,$headers);,
Download and install the emailOnApproved plugin. You can download my modified (and corrected) version here:
http://www.thecmsbcookbook.com/downloads/emailOnApproved.zip
This modified plugin will allow you to set up a manual approval process and send an e-mail to your new members when they are approved.
Before encrypted passwords it was easier to email login credentials to a member after their account had been manually approved. (Their application was approved, their payment had been verified, etc.)
Since the implementation of encrypted passwords, the process became a bit more involved.
Here’s are the steps necessary:
First, create a visible password text field in the “Accounts” section (I call it visible_password in this recipe)
Then have your signup form automatically fill the visible_password field with the automatically generated password before it’s encrypted.
You’ll need to comment out (or remove) the send email instructions in the signup form
You’ll also want to change the “show thanks” message that is presented on a successful signup.
Then in the emailOnApproved plugin, you’ll want to change the ‘password’ field to ‘visible_password’
Here are the specifics:
First add a text field called visible_password to your “accounts” section. (You can call it anything you want to, but be consistent)
Then open your signup form and somewhere in the mysql_query("INSERT INTO `{$TABLE_PREFIX}accounts` SET code insert the following code as a separate line:
visible_password = '$password',
it doesn’t matter where in the series you insert the line, as long as it’s a separate line.
Next search for // send message and comment out the entire section with a after the section like this:
Just under that section of code you should find the section called // show thanks
You’ll want to modify that message to something like:
$errorsAndAlerts = "Thanks, We've created an account for you. As soon as you're approved we'll email you your password.\n";
$errorsAndAlerts .= "If you don't receive an email from us within a few minutes check your spam filter for messages from {$SETTINGS['adminEmail']}.\n";
// $errorsAndAlerts .= "<a href='{$GLOBALS['WEBSITE_LOGIN_LOGIN_FORM_URL']}'>Click here to login</a>.";
Notice that I’ve removed the reference to {$emailHeaders['from']} in the “spam filter” text and replaced it with {$SETTINGS['adminEmail']} (you’ll get an error if you don’t because you removed the original variable in the previous step) , and commented out the login URL line with a double forward slash (you can remove this line if you’d prefer).
Now save your signup form and open the emailOn Approved plugin.
The instructions on how to implement this plugin are below.
Search for ‘password’ and replace this with ‘visible_password’ (unless you called your field something else)
That’s it.
______________________________________________________
______________________________________________________
LEGACY INFORMATION
BACKGROUND
When I first activated the original emailOnApproved plugin, I was getting Undefined index errors reported on saving a record until I added this line suggested by Dave Edis to the error checking section of the code:
if ($Table name != 'accounts') { return; }
So now the error checking section looks like
// error checking
if ($tableName != 'accounts') { return; }
if (!array_key_exists($fieldname, $CURRENT_USER)) {
die(__FUNCTION__ .": You must create an accounts fields called '$fieldname'!");
}
And there are no more Undefined index errors.
I decided that it would make more sense to include the new member’s username, temporary password and a login URL in this email, so I modified the original:
// send email
$wasChecked = intval(!$oldRecord[$fieldname] && $_REQUEST[$fieldname]);
$wasUnchecked = intval($oldRecord[$fieldname] && !$_REQUEST[$fieldname]);
if ($wasChecked) {
$errors = sendMessage(array(
'from' => $SETTINGS['adminEmail'],
'to' => $_REQUEST['email'],
'subject' => "You have been approved!",
'text' => "Congradulations!
You have been approved for our website.
Your password is: {$_REQUEST['password']}
See you soon!
",
));
if ($errors) { die($errors); }
}
}
?>
To this:
NOTE: Make sure that there are no spaces after the $message=<<< __TEXT__ and that the __TEXT__; is flush against the left margin or you’ll generate errors.
// send email
$wasChecked = intval(!$oldRecord[$fieldname] && $_REQUEST[$fieldname]);
$wasUnchecked = intval($oldRecord[$fieldname] && !$_REQUEST[$fieldname]);
$message=<<< __TEXT__
Congratulations!
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_web_site_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 = $errors=mail($_REQUEST['email'],"Your membership has been processed!",$message,$headers);
if ($errors!=1) { die("Mail Error: $php_errormsg"); }
}
}
?>
The first CMS Builder reference book is now available on-line!
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php