USING THE BUILT IN "MAILARRAY" FUNCTION TO SEND EMAILS - Aug 23rd, 2014


Using the mailArray function built in to CMS Builder seems to be more robust then using sendmail directly.

CAVEAT: Make sure that the 'from' address and the 'to' address are real, or your mailserver may kick your email back
with no specific error message. I had a .com instead of a .org as the TLD in an admin email address, and since there was
no .com domain, the password change email, supposedly coming from the admin email address, was kicked back by the server
as invalid and never got delivered. I guess that applies to those noreply@noreply.com email return addresses as well.

The basic implementation for the mailArray function is:


<?php
$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);
?>


If you're pulling the to: value from a multi-record editor, you may want to delay execution of the individual emails
and reset the PHP max_execution time. If so, insert this before the $errors code above



// delay execution by .2 sec
usleep(200000);
// reset max_execution_time to 30 sec
set_time_limit(30);


To make sure that the maximum length of a line in your email does not exceed 70 characters (a stipulation in the PHP
email function spec), you may want to include this code just after the $message variable:



<?php $message = wordwrap( $message, 70); ?>



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