I have created PHP app and deployed using heroku. In the app, I have contact form to send mails to my gmail account. To implement this, I have written the following PHP code
Heroku doesnt allow send e-mails, you must use external SMTP server.
"To send emails from applications deployed to Heroku, use an external SMTP service." https://devcenter.heroku.com/articles/smtp
How to send e-mails throw SMTP is described here: Sending email with PHP from an SMTP server