SENDING EMAILS FROM A MULTI-RECORD EDITOR USING MAILARRAY FUNCTION - Nov 16th, 2012


Recent versions of CMS Builder have a built in mailArray email function that takes care of many of the issues
encountered when using the PHP mail( ) function alone.

If you use this function in CMS Builder 2.17 (or later) it will log your messages for you if you have the feature
enabled.

Beginning with CMS Builder version 2.50, there are many other new email related features available, including templates
and cron job management.

This is the basic code required to use the mailAray function.


$message = 'This is a test message';
$mailArray = array(
'to' => 'example@example.com',
'from' => 'example@example.com',
'subject' => 'This is a subject',
'html' => $message
);
$errors = sendMessage($mailArray);


To use this function to send emails to recipients in a multi-record table, you could use something like:



<?php //reset counter so emails sent can be counted
$email_count = '' ?>
<?php foreach($your_tableRecords as $record) : ?>
<?php $the_to = $record['email']; ?>
<?php $first_name = $record['first_name'] ; ?>
<?php $last_name = $record['last_name'] ; ?>
<?php ob_start(); // start capturing output ?>
<?php foreach ($your_tableRecords as $record): ?>
<?php if($the_to == $record['email']) : ?>
<?php $recnum = $record['num'] ?>
<?php endif; ?>
<?php endforeach ?>
<?php $output = ob_get_clean(); // stop capturing output ?>
<?php $variable1 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vulputate, est vitae convallis
hendrerit, risus nulla iaculis urna, viverra euismod tortor sem eget felis.

Aliquam erat volutpat. Maecenas ac purus justo. Vivamus tortor leo, tincidunt sit amet rhoncus bibendum, faucibus vitae
neque.

Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Duis id velit sed leo dignissim
hendrerit id sit amet ligula. Nam iaculis, mi suscipit varius dignissim, ligula lectus eleifend est, vitae sollicitudin
orci arcu facilisis tortor. Vivamus adipiscing diam vitae ipsum adipiscing euismod." ?>
<?php //limit line length to no more than 70 characters
$variable1 = wordwrap($variable1, 70); ?>
<?php $email_count++ ; ?>
<?php
$message = <<<EOF
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type content='text/html; charset=utf-8" />
<style type="text/css">
.body-text {font-family:Arial; font-size: 1.0em;}
</style>
</head>
<body >
<div align='left'><img src='http://www.your_domain.com/email_open.php?num=$recnum' height='1' width='1' alt='' /><img
src='http://www.your_domain.com/images/LOGO.png' width='800' height='183' style='border:hidden'/></div>
<div align='left' class='body_text'>
Hello $first_name $last_name,

$disclaimer \r\n

$output \r\n

Please be aware that metus id nibh porttitor faucibus. Integer nec urna risus, in cursus enim. Nulla hendrerit, sem non
hendrerit molestie, dui urna tempus dui, sit amet bibendum orci tortor ac metus. Proin ac scelerisque neque.\r\n
</div>
</body>
</html>
EOF;
$the_from = "you@your_domain.com";
$the_subject = "This is the email subject";

$mailArray = array(
'to' => $the_to,
'from' => $the_from,
'subject' => $the_subject,
'html' => $message
);
$errors = sendMessage($mailArray);
// delay execution by .1 sec (optional if sending anomilies occer, try this)
usleep(100000);
// reset max_execution_time to 30 sec (or your value from php.ini)
set_time_limit(30);
?>
<?php endforeach ?>
<?php if ($email_count && !$email_count == '0' ):?>
<span class="your_class">*** </span>You have sent <?php echo $email_count ?> emails.
<?php endif; ?>




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