Sending e-mail when fails goes stucked and do nothing

Hello,
I got to understand how to fix the issue .
When I do the mail sending test I got only the message if all is correct.
If Ok I show the message correctly , if not , nothing appears and the application goes stucked with a empty page .
Is there any reason ? I need to show an error to user and avoid stucking of application.

Thanks

if ({sc_mail_ok})
{
echo '<script type="text/javascript">alert("Attenzione !

Verificare la copia del messaggio inviato nella vs casella e-mail");</script>’;
$sent_flag = 1;
// Update field Mail_sent to 1

    if ($sent_flag == 1)
    {
    $Sql_mail_sent="UPDATE orders  SET Mail_sent = 1 WHERE `OrderID` = [glo_OrderID]";
    sc_exec_sql($Sql_mail_sent);
    }

}
else
{
    sc_error_message({sc_mail_erro});
    sc_alert(" Message delivery failed...");

// sc_error_message(“Attention Customer, Agent, Manager E-mail not present or not correct !!!”);
// echo “<script type=‘text/javascript’>alert(“Attention Customer, Agent, Manager E-mail not present or not correct !!!”);</script>”;
}