Email template placeholders?

4 posts by 2 authors in: Forums > CMS Builder
Last Post: November 26, 2018   (RSS)

Hi Guys.

I've using form builder plugin to create a form.  "Name of resident" is a multi-select checkboxes.

I've added:

 	    // Send Admin Alert via Email Template
			$emailHeaders = emailTemplate_loadFromDB(array(
			    'template_id'  => 'REGIS-TO-ADMIN',
			    'placeholders' => array(
			      'user.start_date'     => $_REQUEST['start_date'],
			      'user.start_time'    => $_REQUEST['start_time'],
			      'user.name_of_resident'    => $_REQUEST['name_of_resident'],
			      'user.end_time'    => $_REQUEST['end_time'],
			      'user.description_of_visit'    => $_REQUEST['description_of_visit'],
			      'user.summary_of_visit'    => $_REQUEST['summary_of_visit'],
			      'user.next_visit'     => $_REQUEST['next_visit'],
			
			  )));
			$mailErrors   = sendMessage($emailHeaders);

The data is added to the CMSB table just fine, but I get the error as detailed below, which I think is caused by trying to convert the string to a placeholder for the email?

E_NOTICE: Array to string conversion

Filepath: /home/XXX/public_html/cmsAdmin/lib/common.php

Line: 1733

#0 _errorlog_logErrorRecord() called at [/home/XXX/public_html/cmsAdmin/lib/errorlog_functions.php:62]
#1 _errorlog_catchRuntimeErrors() called
#2 str_replace() called at [/home/XXX/public_html/cmsAdmin/lib/common.php:1733]
#3 emailTemplate_replacePlaceholders() called at [/home/XXX/public_html/cmsAdmin/lib/common.php:1662]
#4 emailTemplate_loadFromDB() called at [/home/XXX/public_html/regis.php:80]

Cheers,

Tim (toledoh.com.au)

Thanks Greg.

Do you think it would be a simple process to loop the send email function for every checkbox?  ie. if 1 resident is selected, 1 email is sent.  If 3 residents are selected, loop the send function 3 times, each with a different vale in the placeholder?

The reason for this is that the email template is structured grammatically for a single person.  It's not a big issue, but may be nicer to send an email per resident.

Cheers,

Tim (toledoh.com.au)

Hey Tim,

That shouldn't be too difficult, you'd have to update the multiselect name_of_resident field so that its the email_of_resident instead, then ensure its value contains the email to send to, then you could use the code below to send the email:

if(is_array($_REQUEST['email_of_resident'])) {
  foreach($_REQUEST['email_of_resident'] as $email) {
    // Send Admin Alert via Email Template
    $emailHeaders = emailTemplate_loadFromDB(array(
      'template_id'  => 'REGIS-TO-ADMIN',
      'placeholders' => array(
        'user.start_date'           => $_REQUEST['start_date'],
        'user.start_time'           => $_REQUEST['start_time'],
        'user.email_of_resident'    => $email,
        'user.end_time'             => $_REQUEST['end_time'],
        'user.description_of_visit' => $_REQUEST['description_of_visit'],
        'user.summary_of_visit'     => $_REQUEST['summary_of_visit'],
        'user.next_visit'           => $_REQUEST['next_visit'],
    )));
    $mailErrors   = sendMessage($emailHeaders);
  }
}

Something to keep in mind, if the value in the multi-select field is the email address anyone who's on the page could see the email addresses if they viewed the HTML, so I'd not recommend using this method on a public page.

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com