Most web hosting providers restrict relaying of emails through the hosted scripts without email authentication. Also, there could be issues with the IP reverse DNS lookup which prevents you from your using the server hosting your app for email deliveries.

In such cases, the developer can opt for integrating a third party cloud based transactional email relay service like Mailgun or Mandrill. But these are free for use till a certain no. of emails/month. If your application is still under development and you have a very low outgoing email requirement, you may optionally use Gmail SMTP for relaying those emails through your free Gmail login. But please remember that Gmail may block you from sending further emails in case you send too much transactional emails this way.

In order to achieve this you need to make change in two security settings of your Google account. These will make you Gmail account more vulnerable to hacking and abuse. So be careful not to do so on your main Google account.

google-signing-in-security

As seen in the above screenshot, you have to set 2-Step Verification to Off and Access for less secure apps to Allowed in the Signing in section of your Google account settings.

Now use Google SMTP in your mailing code with following settings –

SMTP Server: smtp.googlemail.com

SMTP Port: 465

Enable SSL: True

Also please keep into mind that many hosting providers do not allow outgoing connections to port 465 from the web applications hosted on their server. Hence, you may have to ask your provider to allow such connectivity. If you are hosting on a server or local system under your full control, then you may allow the outgoing to 465 port using the following iptables rule –

iptables -A OUTPUT -p tcp –dport 465 -j ACCEPT