PAM report template issue

i am trying to add this script to the report template to send email . I took it from the documentation but it is not working.

any help to solve this issue? please i need steps also 

this is the script :

<%!
my @lvl0;
my @lvl1;
my @lvl2;
my @lvl3;
my @gt0;
my @gt5;
my @gt10;
my @gt20;
%>
<%
my @audit_records = @{$tokens->{'AuditRecords'}->{'AuditRecord'}} if (defined($tokens->{'AuditRecords'}) && defined($tokens->{'AuditRecords'}-
>{'AuditRecord'}));
foreach my $ar (@audit_records) { my $age = $ar->{'age'};
my $lvl = $ar->{'level'};

if ($age > 5 && $age < 10) { push(@gt5,$ar);
} elsif ($age >= 10 && $age < 20) {

push(@gt10,$ar);
} elsif ($age >= 20) { push(@gt20,$ar);
} else { push(@gt0,$ar);
}
if ($lvl == 1) { push(@lvl1,$ar);
} elsif ($lvl == 2) { push(@lvl2,$ar);
} elsif ($lvl >= 3) { push(@lvl3,$ar);
} else { push(@lvl0,$ar);
}
}
%>
<%
my $total = @audit_records; if ($total > 0) {
%>
<style type="text/css">
<!--
.style1 { color: #000000;
font-family: Arial, Helvetica, sans-serif; font-size: 12px;
}
.style2 { color: #000000;
font-family: Arial, Helvetica, sans-serif; font-size: 12px;
font-weight:bold;
}
.style4 { color: #000000
}
-->
</style>
<p class="style1"> Hello $User.ACT_FULL_NAME.value$,<br/>
<br/>
This is an automated event notification email from the Compliance Auditor. <br/>
<br/>

It is the responsibility of management to log into the Compliance Auditor each day and review their team's keystroke logs. <br/> <br/>

Please log on to the Compliance Auditor at your earliest convenience using this link: <a href="https://admin.company.com">https://admin.company.com</a>
</p>

<%
my $gt0 = @gt0;
%>
<span class="style2">Events &lt; 5 days old (<%= "$gt0" %>)</span>
<table border="1">
<tr class="style1">
<td>Time</td>
<td>User</td>
<td>Run As</td>
<td>Host</td>

<td>Command</td>
</tr>
<%
foreach my $ar (@gt0) {
my $cmd = $ar->{'cmdctrl'}->{'cmd'};
my $usr = $ar->{'cmdctrl'}->{'user'};
my $ras = $ar->{'cmdctrl'}->{'runAs'};
my $hst = $ar->{'cmdctrl'}->{'host'};
my $tme = $ar->{'cmdctrl'}->{'time'};
$tme = localtime($tme);
%>
<tr class="style1">
<td><%= "$tme" %></td>
<td><%= "$usr" %></td>
<td><%= "$ras" %></td>
<td><%= "$hst" %></td>
<td><%= "$cmd" %></td>
</tr>
<%
}
%>
</table>
<br/>

<%
my $gt5 = @gt5;
%>
<span class="style2">Events &gt; 5 days old (<%= "$gt5" %>)</span>
<table border="1">
<tr class="style1">
<td>Time</td>
<td>User</td>
<td>Run As</td>
<td>Host</td>
<td>Command</td>
</tr>
<%
foreach my $ar (@gt5) {
my $cmd = $ar->{'cmdctrl'}->{'cmd'};
my $usr = $ar->{'cmdctrl'}->{'user'};
my $ras = $ar->{'cmdctrl'}->{'runAs'};
my $hst = $ar->{'cmdctrl'}->{'host'};
my $tme = $ar->{'cmdctrl'}->{'time'};
$tme = localtime($tme);
%>
<tr class="style1">
<td><%= "$tme" %></td>
<td><%= "$usr" %></td>
<td><%= "$ras" %></td>
<td><%= "$hst" %></td>
<td><%= "$cmd" %></td>
</tr>
<%
}
%>
</table>
<br/>

<%
my $gt10 = @gt10;

%>
<span class="style2">Events &gt; 10 days old (<%= "$gt10" %>)</span>
<table border="1">
<tr class="style1">
<td>Time</td>
<td>User</td>
<td>Run As</td>
<td>Host</td>
<td>Command</td>
</tr>
<%
foreach my $ar (@gt10) {
my $cmd = $ar->{'cmdctrl'}->{'cmd'};
my $usr = $ar->{'cmdctrl'}->{'user'};
my $ras = $ar->{'cmdctrl'}->{'runAs'};
my $hst = $ar->{'cmdctrl'}->{'host'};
my $tme = $ar->{'cmdctrl'}->{'time'};
$tme = localtime($tme);
%>
<tr class="style1">
<td><%= "$tme" %></td>
<td><%= "$usr" %></td>
<td><%= "$ras" %></td>
<td><%= "$hst" %></td>
<td><%= "$cmd" %></td>
</tr>
<%
}
%>
</table>
<br/>

<%
my $gt20 = @gt20;
%>
<span class="style2">Events &gt; 20 days old (<%= "$gt20" %>)</span>
<table border="1">
<tr class="style1">
<td>Time</td>
<td>User</td>
<td>Run As</td>
<td>Host</td>
<td>Command</td>
</tr>
<%
foreach my $ar (@gt20) {
my $cmd = $ar->{'cmdctrl'}->{'cmd'};
my $usr = $ar->{'cmdctrl'}->{'user'};
my $ras = $ar->{'cmdctrl'}->{'runAs'};
my $hst = $ar->{'cmdctrl'}->{'host'};
my $tme = $ar->{'cmdctrl'}->{'time'};
$tme = localtime($tme);
%>
<tr class="style1">
<td><%= "$tme" %></td>
<td><%= "$usr" %></td>
<td><%= "$ras" %></td>

<td><%= "$hst" %></td>
<td><%= "$cmd" %></td>
</tr>
<%
}
%>
</table>
<br/>

<p class="style2">Total Events = <%= $total %></p>

<%
}
%>