How to Use the ACYMailing Queue to Send Email

How to Use the ACYMailing Queue to Send Email

There is now a PHP Class (see PHP Objects) that provides a pretty painless way to send an email to one or more recipients. It can be used to send one email to one person, or to send the same email to a group of people. It can also be invoked repeatedly to send different (e.g., personalized) emails to a goup of recipients.

Required Information

To create an instance of the mailer, it’s necessary to tell Joomla where to find its definition. This is done by the following statement, which you can see in the website’s PHP template file /fhaphp/A_MYSQLI_TEMPLATE.php (All PHP examples are case-sensitive!):

JLoader::registerPrefix(‘Fha’, JPATH_LIBRARIES . ‘/fhalib’);

To instantiate the ACYMailer class, use the following code:

$mailer = new FhaACYMailer;

This call creates an object called $mailer. The $mailer object has a number of “methods” (callable functions) and one property.

The methods to set up an email to be sent are these:

  • $mailer->setSubject($subj);    //  Provide the email’s subject line (characters)
  • $mailer->setBody($text);    //  Provide the body of the email (characters with HTML markup)
  • $mailer->setTo($dest);    //  Provide one or more email addresses. If one, it’s characters. If many, a 1-D array of character-type emails

These three definitions are required before the email can be sent. There are optional values that can be sent, listed below. The error array will identify any emails that are not recognizable as valid emails. See discussion below about error returns.

To queue the message for sending, execute the following code:

$result = $mailer->queueEmail();    //  Send email

This method (function) will check to see that all values necessary to queue the email are present, and if so, will create an entry in the ACYMailing queue to send the email to its recipients.

The $result variable returned from queueEmail will be TRUE or FALSE: TRUE indicates that the message was queued and will be sent at the next poll of the queue (which occurs every 15 minutes).

If $result is FALSE the program should interrogate and print the $mailer->errs array to determine what errors were found. one way to do this is to use the debugging printout function loaded by the PHP template. One crude way of terminating the program on errors might look like this:

if ( $result == FALSE ) {
    pr ( $mailer->errs, ‘Errors detected by ACYMailer’);

 Optional Information

To set
Code Where

$mailer->setTemplete($tempid)$tempid is the integer-type ID of the ACYMailing template you want to use. Default is 25, which specifies no formatting except font.

$mailer->setFromName($sname)$sname is the human-readable name of the sender, character-type. Default is the user’s login name.

$mailer->setFromEmail($semail)$semail is the email of the sender, character-type. Default is the user’s logon email.

$mailer->setReplyName($rname)$rname is the reply-to human-readable name for the email, character-type. Default: “Do Not Reply To this Email” 

$mailer->setReplyEmail($remail)$remail is the reply-to email for the email, character-type. Default is