Unfortunately, the username and password you have entered do not match!

Registration

Unfortunately, this username is already taken!

Unfortunately, this e-mail address is already used!

Please retype the verification code.

All fields are required

RSForm!Pro - How to store the submission in a file and send it through the email

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.

The following script will work only with the latest version of RSForm! Pro. 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

Note:

You have to fill in the rest of the email fields (leave none empty).
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.

Feedback