Email form plugin

Jul 11, 2017
Email form plugin
  • 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 (top)


    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. (since 3.0.7)

    Options (top)

    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:
    Version 3.1b and newer 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.

    Attachments(top)

    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(top)

    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(top)

    PHP:

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

    Conditional sending(top)

    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.

    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(top)

    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 (top)


    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(top)

    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'];
      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'];
    $myId = is_array($myId) ? $myId[0] : $myId;
    if (!empty($myId)) {
       $myUser = JFactory::getUser((int)$myId);
       return $myUser->get('email');
    }
    return '';
     

    Email's not sending?(top)

    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 (up to 12,000 emails a month), take a look at http://sendgrid.net.[/php]
  • Loading...