Let's say a user submits a form to submit.php, the server will return two possible responses: A or B. If the server is going to return B, then I'd like the server to send an email to an address.
<?php
if(B){
echo 'B';
}
mail($to, $subj, $msg);
?>
The problem is that it often takes some time to wait mail() to finish... the user can only get responses after the server finishes mail(). This is a very bad experience for my users.
Is there any way that the server can return response 'B' to the user immediately, then it sends mail?