If I understand you correctly, you can simply create a script domail.php that calls the function. Then you would set the form action as action=domail.php (if the button is the submit button to a form), or the link destination as href=domail.php (if the button is a hyperlink).
domail.php
include("file/with/mail/function.php");
mailfunc();