I want to send by mail the selected record in a list view after custom button click.
Followed the example provided in the help file, but no success.
List view

Table: litigios

Custom button "Enviar Mail" in list view with following code :
On server
global $dal;
$dal_TableName = $dal->Table("litigios");
$body="";
foreach(@$keys as $keyblock)
{
$arr=split("&",refine($keyblock["lit_id"]));
if(count($arr)<1)
continue;
$arr2=array();
$arr2["lit_id"]=urldecode(@$arr[0]);
$where = KeyWhere($arr2);
$rstmp = $dal_TableName->Query($where,"");
$datatmp=db_fetch_array($rstmp );
$body .= "ID: " . $datatmp['lit_id'] . "\n";
$body .= "Loja: " . $datatmp['lit_loja'] . "\n";
$body .= "Data: " . $datatmp['lit_data'] . "\n-----------\n\n";
}
// send the email
$email="sribeiro@cooplecnorte.pt";
$subject="Abertura Litigio";
$arr = runner_mail(array('to' => $email, 'subject' => $subject,
'body' => $body));
$result["txt"] = "Email enviado.";
// if error happened print a message on the web page
if (!$arr["mailed"])
{
$errmsg = "Erro:
";
$errmsg.= "Ficheiro: " . $arr["errors"][0]["file"] . "
";
$errmsg.= "Linha: " . $arr["errors"][0]["line"] . "
";
$errmsg.= "Descricao: " . $arr["errors"][0]["description"] . "
";
$result["txt"] = $errmsg;
}
On Client After
var message = result["txt"];
ctrl.setMessage(message);
No mail sent after record selection and "Enviar Mail" button clicked.
The button stays inactive until the page is refreshed.

Don't know where the problem is.
Best regards.
Sérgio