How to store the submission in a file and send it through the email

In this article we will describe how to store the submission in a file and send it through the email. Here's what you need to do:

  1. In the PHP Email Scripts area, type this code (either in the "Script called before the User Email is sent." area or the "Script called before the Admin Email is sent.", depending on what you require. The only difference is that you will have to use the $adminEmail variable or the $userEmail variable):

    // This is the path where we will store the data.
    $file = JPATH_SITE.'/tmp/test.txt';
    // You can make it unique by uncommenting the below line (ie. remove //)
    // $file = JPATH_SITE.'/tmp/'.uniqid('test').'.txt';
    // Initialize an empty $data string. This will hold our processed data.
    $data = '';
    // Loop through all of the submitted data and add it to $data.
    foreach ($_POST['form'] as $name => $value) {
      // If it's a multiple selection (eg. checkbox, dropdown) we'll have to separate the values by a comma.
      if (is_array($value)) {
        $value = implode(', ', $value);
      // Write the name and value pair (eg. First Name=Jack) to $data
      $data .= "$name=$value\r\n";
    // Now, store $data in the $file.
    file_put_contents($file, $data);
    // This is specific to RSForm! Pro - $adminEmail['files'] contains a list (an array) of all of the files that will be attached to the email.
    $adminEmail['files'][] = $file;
    // You can also use $userEmail in the same way, if you're using this script for the User Email.
    // $userEmail['files'][] = $file;
  2. Make sure that the "tmp" folder in your Joomla! root is writable.

  3. Go to the Admin Emails, and customize it similar to this:

    From: support@yourwebsite.com
    To: youradminthatreceivesthefile@yourwebsite.com
    Remember to also add a Subject and some contents to your email message.

Here's how it will work:

1. The user submits
2. The system writes test.txt in "tmp/test.txt"
3. The system attaches this file to the mail sent to the admin.

17 persons found this article helpful.

Was this article helpful?

Yes No
Sorry about that

You Should Also Read

Automatically grab article author email

Retrieve author email address in Sobi2