Skip to Content Skip to Menu

Community Builder has functions to easily allow e-mailing. These functions support substitions allowing you to place field values within your e-mails as well as even attaching files!

The following function is the proper usage of Community Builders E-Mail functions. This will allow you to add e-mailing to any of your projects easily with a copy and paste. All need be is to provide the necessary data for the e-mail to send.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function sendMail( $user_id, $mailTo, $mailSubject, $mailBody, $mailHtml = 0, $mailFrom_email = null, $mailFrom_name = null, $mailCC = null, $mailBCC = null, $mailAttachments = null ) {
 global $_CB_framework;
 
 $cbUser = CBuser::getInstance( $user_id );
 
 if ( ! $cbUser ) {
 $cbUser = CBuser::getInstance( null );
 }
 
 $mailTo = $cbUser->replaceUserVars( $mailTo, false );
 $mailCC = $cbUser->replaceUserVars( $mailCC, false );
 $mailBCC = $cbUser->replaceUserVars( $mailBCC, false );
 $mailSubject = $_CB_framework->getCfg( 'sitename' ) . ( $mailSubject ? ' - ' . $cbUser->replaceUserVars( CBTxt::T( $mailSubject ), false ) : null );
 $mailBody = $cbUser->replaceUserVars( CBTxt::T( $mailBody ), false );
 $mailAttachments = $cbUser->replaceUserVars( $mailAttachments, false );
 
 if ( $mailTo ) {
 $mailTo = preg_split( ' *, *', $mailTo );
 } else {
 $mailTo = null;
 }
 
 if ( $mailCC ) {
 $mailCC = preg_split( ' *, *', $mailCC );
 } else {
 $mailCC = null;
 }
 
 if ( $mailBCC ) {
 $mailBCC = preg_split( ' *, *', $mailBCC );
 } else {
 $mailBCC = null;
 }
 
 if ( $mailAttachments ) {
 $mailAttachments = preg_split( ' *, *', $mailAttachments );
 } else {
 $mailAttachments = null;
 }
 
 if ( $mailTo && ( $mailSubject || $mailBody ) ) {
 if ( comprofilerMail( $mailFrom_email, $mailFrom_name, $mailTo, $mailSubject, $mailBody, $mailHtml, $mailCC, $mailBCC, $mailAttachments ) ) {
 return true;
 }
 }
 
 return false;
}


Passing substitutions as outlined in the substitutions tutorial through to, subject, body, cc, bcc will translate to the appropriate value of the $user field value. This function can also be used to send emails to non-registered users as long as a valid to address is specified (subsitutions of course won't function for non-existant users).