Add user star function triggering PHPmailer email optimisation
Lock the UI until a response comes back (or a reasonable timeout
occurs) to prevent the multiple clicking.
Don't send emails directly from the code, push them to spool or MQ and process separately


As for the code itself - there's nothing much to comment except that it's completely out of touch with modern best practices in PHP world. Consider using a proper framework, ORM or at least a DBAL. See phptherightway for more details.