yem
yem

Reputation: 755

Send email from Heroku server using gmail account and PHPMailer

I have a Heroku app which has a php script that send out an email. The email sent always goes to spam. I know that this question has been asked many times before, but I haven't been able to find a solution that helped me solve the issue for a Heroku website without a custom domain while using a gmail acount.

Let's say the heroku app is mywebsite.herokuapp.com and my email is [email protected]. 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, but it seems like sending it through a gmail account might make this not an issue?

Server Settings:

$mail->isSMTP();                                            
$mail->Host       = 'smtp.gmail.com';                    
$mail->SMTPAuth   = true;                              
$mail->Username   = '[email protected]';                    
$mail->Password   = 'secretpassword';                              
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;        
$mail->SMTPSecure = 'ssl';
$mail->Port       = 465;  

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.

This link gave a lot of general (very helpful) information but I can't tell from this whether or not there is a solution for my situation. This was the closet that I got to helpful information but it didn't give me enough information to go on.

Any suggestions?

Thanks

Upvotes: 1

Views: 207

Answers (1)

Synchro
Synchro

Reputation: 37710

Fundamentally, you simply cannot send from a gmail address if you're not sending through gmail's servers. Their SPF, DKIM and DMARC records won't allow it. Furthermore, you can't send from a gmail address that isn't yours, or a predefined alias of yours.

PHPMailer has some docs on avoiding spam filters (essentially by not looking like something they would want to block), but there's not a lot you can do.

Upvotes: 1

Related Questions