1

Trying to send email using mailtrap... i successfully implemented it on localhost and it works fine, however i can't get it to work on live server after deploying to heroku. please what's the fix around it

here is my smtp settings from my .env file

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=31239f96d871e7
MAIL_PASSWORD=*****
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="browynlouis2@gmail.com"
MAIL_FROM_NAME="${APP_NAME}"

and that's exactly how it is in my heroku

Morri
  • 37
  • 2
  • 9
  • Most reputable servers will not send mail unless the from address is an email address registered within the hosting account doing the sending. Helps a bit to stop a casual spammer – RiggsFolly Jul 11 '22 at 15:25
  • 1
    Can't flag as duplicate, but check this question/answer: https://stackoverflow.com/questions/66241040/mailtrap-error-expected-response-code-250-but-got-code-550-with-message-55. Seems to be something with MailTrap + Heroku maybe? – Tim Lewis Jul 11 '22 at 15:26
  • @TimLewis i already did as said in the link you shared, i added the config of my mailtrap to heroku already – Morri Jul 11 '22 at 15:29
  • @RiggsFolly is there a better alternative to this please – Morri Jul 11 '22 at 15:30
  • 1
    At the risk of repitition ... But this email address `MAIL_FROM_ADDRESS="browynlouis2@gmail.com"` is not a valid email address on your hosting account, its a gmail address. If you site is for example `example.com` you need an email address like `something@example.com` – RiggsFolly Jul 11 '22 at 15:30
  • @RiggsFolly for now i can't use it as that... is there another way around me doing this – Morri Jul 11 '22 at 16:06
  • Well if I am right, and the server will not allow email to be sent from a randon, unknown account from their server (bit like allowing an open relay) Then NO THERE IS NO OTHER WAY AROUND THIS – RiggsFolly Jul 11 '22 at 16:08
  • have you cleared the config since making changes? And restarted queue workers? – Snapey Jul 11 '22 at 22:20
  • @RiggsFolly Mailtrap will never reply with relay not allowed. So the from address is irrelevant – Snapey Jul 11 '22 at 22:23
  • i got it to work... i add to install Mailtrap addon on Heroku before i could use it.. then cleared config afterwards – Morri Jul 12 '22 at 08:50

1 Answers1

1

For live server like hostinger change .env setup for smtp

.....................................................................................................................

Mail_Mailer=smtp

Mail_Host=smtp.hostinger.com

Mail_Port=465

Mail_Username=example@domain.com

Mail_Password=password

Mail_encryption=ssl

Mail_From_Address=example@domain.com

MAIL_FROM_NAME="${APP_NAME}"

then go to config/mail.php change transport smtp to mail

'mailers' => [

    'smtp' => [

        'transport' => 'mail',      //before it was smtp

        'host' => env('MAIL_HOST', 'smtp.mailgun.org'),

        'port' => env('MAIL_PORT', 587),

        'encryption' => env('MAIL_ENCRYPTION', 'tls'),

        'username' => env('MAIL_USERNAME'),

        'password' => env('MAIL_PASSWORD'),

        'timeout' => null,

        'local_domain' => env('MAIL_EHLO_DOMAIN'),

    ],
MShaba007
  • 56
  • 4