SENDING EMAILS TO "MEMBERS" - Feb 7th, 2012


When Christopherb wanted to be able to send emails to all members using CMS Builder, Jason Sauchuk from Interactive
Tools had this suggestion.

According to Jason:

There's a function in CMS Builder called sendMessage() that lets you send emails.

What you can do is set up an HTML form that has 2 fields, one called "subject" and then one called "message". In the
action of this form, you can have the form submit to itself (ie, action = "?" ).

At the top of your script you can use this code:

Code

if (@$_REQUEST['subject'] && @$_REQUEST['message'] && $CURRENT_USER['isAdmin']) {

list($membersRecords, $membersMetaData) = getRecords(array(
'tableName' => 'accounts',
'allowSearch' => false,
));

$emailList = join(",", array_filter(array_pluck($memberRecords, 'email')));

sendMessage(array(
'to' => "to@email.com",
'from' => "from@email.com",
'subject' => @$_REQUEST['subject'],
'text' => @$_REQUEST['message'],
'headers' => array(
'BCC' => $emailList,
),
));

}


With the code && $CURRENT_USER['isAdmin'] included, , this code will only execute if the current user is an
administrator and both subject and message were given a value.

What the script does then is get all of the users in "accounts" and create a comma separated list of their emails. It
then sends out an email with all of these emails in it's BCC field. You'll need to change the value of the "to" and
"from" field to whatever emails you'd like to use.




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