It's a common mistake to use PHP native mail() function to send e-mail, it looks easy but in reality, it will not deliver e-mail. The message's header generated by mail() will not make the message relayed by the server or accepted by major mail providers like Gmail, it will be considered spam and will be discarded.
In this tutorial we will use PHPMailer library to send a test message, you can then integrate the code with your own application. Using SMTP to send email will ensure that message will have the proper authentication headers for successful delivery.
1. Create a mailbox @yourdomain.com, or use any existing mailbox @yourdomain, we will use this address for SMTP authentication.
2. Login your 2mhost hosting account via Terminal or SSH (use your domain name as server with your cPanel logins and port 5555)
3. Create a test folder inside your public_html, and switch to it:
4. Clone PHPMailer repository
5. Create the test file
6. Copy/Paste the following code, use your real information (mail server, user name, password, ..etc) and save the file.
7. run the file from the browser: yourdomain.com/test/test.php