As a newly introduced feature, the PHP Email Scripts section offers an increased flexibility in the terms of dynamic email content.
The scripts can be applied to all the RSform!Pro generated emails: User, Admin and Additional Emails. The email can be altered via the $userEmail, $adminEmail and $additionalEmail variables.
These are standard PHP Array variables that contain the following fields:
[to]
[cc]
[bcc]
[from]
[replyto]
[fromName]
[text]
[subject]
[mode]
[files]
Examples:
1) Let's assume that you wish to change the recipient fo the user email based on a drop-down value that has been submitted:
if($_POST['form']['name_of_drop_down'][0] == 'Sample value here') $userEmail['to'] = 'email@domain.com';
2) Let's assume that you wish to remove from the admin email message the placeholders of the fields that were not filled by the user. First, the admin email text will have to be retrieved. This is can be done by using a code line similar to the following one:
$modAdminEmailText = $form->AdminEmailText;
The text of the admin email is stored in $form->AdminEmailText and the whole text is then placed in the $modAdminEmailText variable. Next, we will verify the content of the field which we wish to remove in case it is left blank and remove the field's placeholders if no value is submitted in the field. This can be done in the following way:
if($_POST['form']['your_field_name'] == '') $modAdminEmailText = str_replace('{your_field_name:caption}: {your_field_name:value}','',$modAdminEmailText);
The content of the field is verified in the $_POST variable, which holds the data submitted in all form fields, and then removes the field's placeholders from the admin email text through str_replace if the content of the field is blank. Once the placeholders are removed the text that will be sent in the admin email is set to be the new text and the rest of the placeholders(stored in the $placeholders variable) are replaced with the actual values in the fields(stored in the $values variable):
$adminEmail['text'] = $modAdminEmailText; $adminEmail['text'] = str_replace($placeholders, $values, $adminEmail['text']);






