0

I have a Heroku app which has a php script that send out an email. The email sent always goes to spam.

Let's say the heroku app is mywebsite.herokuapp.com and my email is mywebsite@gmail.com. Based on my research I understand that the problem might be that the email is being sent from my server which is mywebsite.herokuapp.com but the email address is gmail.com.

If I used $mail->Host = 'smtp.gmail.com'; can this be the problem?

Based on my research other problems might be with the SPF or the DKIM

I spent a ton of hours trying to look it up online but everything I found had to do with custom domains and their DNS settings (for a start) which you can't have with a Heroku app.

Any suggestions?

Thanks!

This was the closest that I got to helpful information but it didn't give me enough information to go on.

yem
  • 1
  • 2

1 Answers1

0

You can send mail thru gmail but getting it going is a process. You'll have to generate an app userid/pass and then do the setup steps for your system's MTA (i.e. Postfix/sendmail). I've done this myself several times and it works well. There are sending limits however, even if you have a paid gmail account (i.e. Google for Business).

The source! Google itself says to do it this way: https://support.google.com/a/answer/2956491?hl=en

and one from other users on serverfault: Configure Postfix to send/relay emails Gmail (smtp.gmail.com) via port 587

You can also use services like SendGrid and MailChimp but they'll also want money. Free gmail accounts can do this however the sending limits are much lower.

t3ln3t
  • 379
  • 1
  • 7
  • But what if I have the email proccess going, meaning the emails send but if I send it to someone this way it goes to spam automatically until the user marks it as non spam? – yem Jan 01 '22 at 17:17
  • Using DKIM and SPF in conjunction with a commercial mail relay service should keep your mail out of user SPAM folders unless your mails get flagged for something else typical of UCE. – t3ln3t Jan 06 '22 at 20:27