Email scheduled task

  • Views Views: 14,040
  • Last updated Last updated:
  • Introduction​


    The email plugin will iterate over each record in the list defined in the plugin's general connection/list Options, and send an email out per record. This can be useful for notifying users.

    The Email scheduled task plugin will only run if the Fabrik Cron System Plug-in is installed.

    Options - details​


    cron-email-options.png


    • To - Email address to send the notification to - can use the table's record's data by using Placeholders e.g. {tablename___elementname}
    • Subject - The email subject - can use the table's record's data by using Placeholders e.g. {tablename___elementname}
    • Message - The email subject - can use the table's record's data by using Placeholders e.g. {tablename___elementname}
    • Eval- Evaluate the Message as PHP code
    • Condition - OPTIONAL PHP to evaluate for each row. The row will not be processed if you return false. Standard element Placeholders can be used, or row data can be accessed from $row array. Remember that this code runs on every row in the list, so keep your code efficient so you don't run in to max execution time issues.

    Options - Update​


    cron-email-update.png

    • Field - select a table's field to update
    • Value - select the value to update to
    • Eval - should we evaluate the update value.
    Update works well in conjunction with a prefilter on the selected list. For example your list may have a prefilter:


    where sent = 0


    In your update field you could select 'sent' and set the value to '1'.


    This would mean that the row is only processed once by the plug-in

    PHP Examples​

    Removing apostrophes from fields for proper html output. This will replace apostrophes of both types, straight and curled from the fields and replace them with encoded values, preventing any errors like "Message Body Empty" when attempting to run the email cron. Reminder: you need to turn Eval on for PHP code to work in the Message textarea.

    PHP:

    //removing apostrophe from fields...
    $personname = "{pfx_listname___name_raw}";
    $personname = preg_replace("/'/", "'", $personname);
    $personname = preg_replace("/?/", "'", $personname);

    //assign $output variable the email body html
    $output = '<p>The new subscriber '.$personname.' sent you a message, login to view it.</p>';

    //send $output back to Fabrik
    return $output;

    PHP Duration Example​

    PHP:

    $myDateElement = strtotime($row->date_time);
    $date = new DateTime();
    $datenow = $date->getTimestamp();
    $datediff = ($datenow - $myDateElement);
    $diff = round($datediff / 86400); //difference in days
    return ($diff == 10); // To send email on 10th day. Change this value to send nth day.
Back
Top