• A new version of Full Calendar is now available.

    See the details here

Email form plugin

  • Views Views: 45,069
  • Last updated Last updated:

Navigation

         Form Article Plugin Tutorial
      Autofill form plugin
      Clone form plugin
      Comment form plugin
      Email form plugin
      EXIF form plugin
      FTP form plugin
      J2store form plugin
      Kunena form plugin
      Limit form plugin
      Log Form Plugin
      Logs form plugin
      Mailchimp form plugin
      Paginate form plugin
      Paypal form plugin
      PHP form plugin
      Pingdotfm form plugin
      Receipt form plugin
      Redirect form plugin
      REST form plugin
      Slack form plugin (+)
      SMS form plugin
      Twitter form plugin
      Upsert form plugin
      VBforum form plugin
      Create a Search Form
      Accordion Form Groups
  • The email plug-in will send an email when the form is submitted.
    All email addresses (To, From, Reply to) must be valid. Make sure that Placeholders contain a valid email address, depending on element type and settings you may have to use {table___element_raw}.

    It has the following Options:

    To​


    email-to.png

    Email to - A comma separated list of email addresses to which the form's data will be sent. Dynamically include form data by entering {tablename___elementname}. Make sure that the placeholder contains a valid email address, depending on element type and settings you may have to use {table___element_raw}. 'Friendly names' are not supported (Fabrik3.4.3).
    Email to (eval) - PHP code to generate an additional set of comma separated email addresses that will be appended to those addresses.
    E.g. :
    return 'rob@test.com,borris@smirnoff.com';
    Send to group - in addition to any 'email to' or 'email to (eval)' email address, send the message to the selected user group(s).

    Options​

    upload_2016-6-18_11-47-39.png

    From - OPTIONAL but if used provide a single address and friendly name to use as the return address. Recent versions of phpMailer require the friendly name, otherwise the email send will fail. E.g. 'my@email.com:John Doe' (do not include the quotes). Can use Placeholders. If left blank, will default to J!'s server default email address.
    Reply to - OPTIONAL a single address to use as the return address. Specify an optional 'friendly names' by separating email and name with a colon : E.g. 'my@email.com:John Doe' (do not include the quotes). Can use Placeholders.
    Subject- The email's subject; Dynamically include form element data by using {tablename___elementname}
    PHP/HTML Template - As default Fabrik will send a dump of all the data submitted by the form. If you need finer control over the output of the email you can specify a template to use.
    Templates can be either html or php files.
    Templates should be located in:
    /plugins/fabrik_form/email/tmpl
    Version older then 3.1b in:
    /components/com_fabrik/plugins/form/fabrikemail/tmpl.
    Article template - If desired you can select a Joomla article to use as a template. This article can use {tablename__elementname} Placeholders which will be replaced with the submitted form content.
    If selected instead of a PHP/HTML template then the content of the article will be emailed
    If selected in addition to a PHP/HTML template the the content of this article will be available for use in the PHP/HTML template via the use of a placeholder '{content}'
    Run Plugins -Run content plugins on message text. Applies to article, PHP and HTML templates.
    Message Text - OPTIONAL - text of message. May use Placeholders. If specified in addition to an article template, the special placeholder {content} will incude the article template text. If used in addition to the PHP/HTML template, the special placeholder {template} will include that text.
    Condition - Optional PHP code. If code returns false, emails will not be sent. The form data is contained within the variable $data. The form's original data is available as an array called $origData
    Email Sent Field - Optionally select an element which will be set to 1 when an email is sent. This also adds an implicit condition on sending, so no email will be sent if this element has a non-zero value. Can be a hidden field, or something like a YesNo radio button.

    Attach Files​

    upload_2016-6-18_11-37-55.png

    Attachment type - OPTIONAL - if a file extension (like csv) is provided, the message content (output of your template) will also be attached with a random filename (using the specified extension). This allows you to create xml/csv files which can then be processed further by the recipient. If not specified, not attachment is sent.
    Attachments (eval) - OPTIONAL - PHP code to add attachments. Code just needs to return an array of full path name(s) to desired file(s). Can use Placeholders, and/or access form data in $this->data.
    PHP:
    $file[] = 'images/your_folder/your_file.pdf';
    return $file;
    Attach as PDF - Attach the submitted record's detail view as a PDF document. The PDF is rendered using the form's PDF template.

    Examples​

    In HTML templates you can insert the form data with Placeholders (see below)
    In PHP templates you can use Placeholders or access the form's data with:
    PHP:
    echo $this->data['tablename___elementname'];
    See also Email templates
    example:

    PHP:
    <table>
    <?php
    foreach ($this->data as $key => $val) {
    echo "<tr><td>$key</td><td>";
    if (is_array($val)) {
    foreach ($val as $v) {
    if (is_array($v)) {
    echo implode("", $v);
    } else {
    echo $v."";
    }
    }
    } else {
    echo $val;
    }
    echo "</td></tr>";
    }
    ?>
    </table>

    Accessing Form's original data​

    PHP:
    $origData = $formModel->getOrigData();
    echo $origData[0]->tablename___elementname . ' has been updated to ' . $this->data['tablename___elementname'];


    Conditional sending​

    Condition - PHP code which should return true or false. If it returns false then the email is not sent. This option can be useful when you only want to send out the email if the user has selected a particular option in your form. Place holders can be used, so a simple example of a condition might be:
    PHP:
    return '{tablename___elementname}' == 1;
    or (depending on element type)
    PHP:
    return '{tablename___elementname_raw}' == 1;

    The Forms's original data is available as an array called $origData. So, to access any of you Forms original data you can do use variables like this...
    PHP:
    $origData["tablename___elementname"]
    Please note you may also need to use the raw form data rather than the field on the form too to make proper comparisons for detecting change - so you just append " _raw " to the elementname.

    For 'onBeforeProcess' hook use:
    PHP:
    $origData = $formModel->getOrigData();
    $origData[0]->tablename___elementname;

    Note for all these Options: to access data submitted by the form you can enter the placeholder "{tablename___elementname}" which will be replaced with the data submitted in that form element.

    More Conditional sending​

    Send the form based on the values of a radio selection (On form Edit)
    PHP:
    if ('{aaa_approval___approve_user}' == approved) {
    return true;
    }
    elseif ('{aaa_approval___approve_user}' == pending)
    {
    return false;
    }


    Utilizing HTML Email Templates​


    WIP- Incomplete

    HTML templates are simple and efficient for sending out an auto-responder or message when someone completes a form. You may choose between an HTML Template that comes pre-installed with Fabrik 3, or you may elect to write your own template.

    All of the pre-installed templates that come with Fabrik have all of the HTML/CSS covered for you. All you will have to do is add your content and change out/add your "{tablename__elementname}" tags.

    Additional Placeholders:

    {emailto}
    {$your->foo} - If found, this is the Joomla user you are mailing to. replace 'foo' with a field from the #__user table, e.g. name, username
    {fabrik_editlink}
    {fabrik_viewlink}
    {fabrik_editurl}
    {fabrik_viewurl}

    Email to (eval) example​

    Say you have a Dropdown element (contact___company) which contains a list of companies. The dropdown values are 'company1', 'company2' and 'company3', and you want to change which email address the email is sent to based on the selected company.

    PHP:
    $company = $this->data['contact___company_raw'];
    switch ($company) {
    case 'company1':
    $email = 'bob@company1.com';
    break;
    case 'company2':
    $email = 'fred@company2.com';
    break;
    case 'company3':
    $email = 'valerie@company3.com';
    break;
    }
    return $email;

    Or if you have a User element (or any element containing a numeric user ID), and you want that user's email ...

    PHP:
    $myId = $this->data['yourtable___youruser_raw'];
    $myId = is_array($myId) ? $myId[0] : $myId;
    if (!empty($myId)) {
    $myUser = \Joomla\CMS\Factory::getApplication()->getIdentity((int)$myId);
    return $myUser->get('email');
    }
    return '';

    Or if you have a join element to a 'staff' table which has an 'email' field ...

    PHP:
    $myEmail = '';
    $staffId ='{yourtable___staff_id_raw}';
    if (!empty($staffId)) {
    $db = Joomla\CMS\Factory::getContainer()->get('DatabaseDriver');
    $query = $db->getQuery(true);
    $query->select('email')->from('staff')->where('id = ' . (int)$staffId);
    $db->setQuery($query);
    $myEmail = $db->loadResult();
    }
    return $myEmail;

    Custom System Message Notification on Email sent​

    PHP:
    Joomla\CMS\Factory::getApplication()->enqueueMessage('Email has been sent {mytable___myelement}', 'message');

    To alter the message type like success, warning, info and error, replace 'message' with following code, what you want:

    'message' for success(green);
    'notice' for info(blue);
    'warning'(yellow);
    'error'(red);


    Email's not sending?​

    99% of the time this is a mail server issue. Its very hard for us to diagnose this, and out of scope for Fabrik support.
    We suggest that you use the free Mandrill web app for sending mail. This is owned by Mailchimp and is the mailing system they use, so you know its going to work.
    Sign up for a free account and create an API key.
    Then install the CMandrill component, ensure that you fill in your API key in the component's configuration page, and that the plugin is published. Now all your site's emails will be sent via the Mandril service, and you get a great dashboard interface showing which emails have been sent.

    NOTE as of early 2016, Mandrill started charging for all account. While it is still a worthwhile service, if you want a reliable free service with a free tier, take a look at http://sendgrid.net or http://mailgun.com.
Back
Top