Replaced mail() with PHPMailer and small fixes