How to Easily Create Notification Emails for Form Submissions in RSForm

We love RSForm – it is by far the best form builder out there. We think that Joomla is blessed to have RSForm in the JED. One of the nicest things about RSForm is that it’s very flexible: there’s always a solution to whatever you want done, regardless of the complexity. OK – enough flirting!

Earlier today (well technically yesterday, since its 1:45 AM here in snowy Montreal) we had a client with quite a few RSForms on her website, and each of these RSForms had literally over a hundred field. The client told us that when someone fills in one of her forms, the notification email that she receives has this single line:

You have a new submission.

Not very helpful! As you have probably guessed, our client wanted to see, in that notification email, all the fields that her clients fill in. This means that we have to manually create the submission email for each form, a task that can take us many hours (remember, our client had many forms, and each one of these forms had over a hundred field). This is not very practical for 3 reasons: 1) we really, really don’t like doing manual work and we avoid it as much as possible, 2) our client’s budget didn’t accommodate the number of hours we estimated if we wanted to manually create these emails, and 3) our client will need to call us to modify these emails every time she adds/edits/removes a field. All in all, doing this task manually seemed to be a far-from-ideal solution. We needed to do it differently!

Thankfully, RSForm allows you to run a script when the form is being processed (e.g. on form submission, just before the form’s information is added to the database). This means that all we need to do is to get all the information that the user filled in from the POST array and email it to the administrator. Let’s explain how we did it:

  • We logged in to the backend of the Joomla website of our client.
  • We went to Components -> RSForm! Pro -> Manage Forms.

  • We clicked on the name of the form.

  • We clicked on the Properties tab on the right (just next to the Components tab, which is selected by default).

  • We clicked on PHP Scripts under Scripts on the left.

  • We added the following code in the Script called on form process textarea:

    $myform = $_POST['form'];
    $body = "";
    $k = 0;
    foreach ($myform as $key=>$value){
    	$k++;
    	if ((!empty($value)) && ($k < count($myform) - 2)){
    		$body .= $key.":".$value."<br />";
    	}
    }
    $mailer = JFactory::getMailer();
    $config = JFactory::getConfig();
    $sender = array('[our-client-email]','[our-client-email]');
    $mailer->setSender($sender);
    $mailer->addRecipient('[our-client-email]');
    $mailer->setSubject('[form-title]');
    $mailer->setBody($body);
    $mailer->isHTML(true);
    $mailer->setBody($body);
    $mailer->Send();

    The above code will send an email with all the filled-in fields to our client.

  • We clicked on the Save button on the top.

  • We then clicked on Admin Emails on the left, and then we removed our client’s email from the To field (this will ensure that our client will no longer get the meaningless You have a new submission email).

  • We clicked on Save on the top right, and then we tested the form, and our little script worked like a charm. Our client was happy, and we were happy!

Good work! But, is there a way to format the notification email?

Of course you can format that email. All you need to do is to add your own formatting to the code above.

What if the form changes?

If the form changes, then the email will change as well, because it’s dynamic. It actually checks which fields the user filled in and only sends the value of those fields to the site owner. This means that any form modification will not affect the integrity of the script.

What if this script doesn’t work for me?

If you have tried our script and it didn’t work for you, then please give us a call or shoot us an email, and we can implement this solution for you in no time and for a very affordable cost!

No comments yet.

Leave a comment