Replace email functions with PHPMailer, a popular open source email sending library.