-3

I have a laravel project, this project has "forgot password" plugin. But when i send reset link to users mail, this link doesnt go to the user mail's inbox. It goes to the my smtp account. I am using mailtrap for testing. I want to be able to send mail directly to user's email. Is it possible to do that with codes. Or should i forward to emails. And how can i do that ? What am i doing wrong ?

What email address they type in this input, reset link should go that email not my mailtrap account.

My reset email link

Password reset link comes here. I dont want that. It has to send reset link to user's email not my mailtrap account.

Email comes here.

Last step should be same but we have to come here from user's email.

enter image description here

Emre Kd
  • 27
  • 5
  • 1
    Show your code PLEASE – Ken Lee Oct 06 '22 at 07:11
  • 1
    _"It goes to the my smtp account"_ - Your code never sends any emails directly to anyone. Your code creates the email and then sends it to your SMTP server. Then your code is done. The SMTP server is then responsible for sending the email to the receiving mail server, which delivers it to the end user. – M. Eriksson Oct 06 '22 at 07:17
  • 1
    Please read [this](https://stackoverflow.com/help/how-to-ask). What have you tried yourself to get it working? – PapaAtHome Oct 07 '22 at 08:26
  • @PapaAtHome look at my answer, i wrote what i did – Emre Kd Oct 07 '22 at 08:46

2 Answers2

1

You're using mailtrap at the moment. This doesn't send any emails to the real world. To receive an email, you must configure correspondence in your .env file.

Default .env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

ex: for Gmail

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=mygoogle@gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=mygoogle@gmail.com
MAIL_FROM_NAME="${APP_NAME}"

Check this example - Laravel 9 Send Mail using Gmail SMTP Server and for configurations

Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
  • Connection could not be established with host smtp.gmail.com :stream_socket_client(): Unable to connect to tcp://smtp.gmail.com:465 (Connection timed out). got this error – Emre Kd Oct 06 '22 at 07:23
  • Try using `587` instead of `465`. – Abdulla Nilam Oct 06 '22 at 07:24
  • @EmreKd check your Gmail username and password is correct `MAIL_USERNAME=mygoogle@gmail.com MAIL_PASSWORD=password` – Abdulla Nilam Oct 06 '22 at 07:26
  • Failed to authenticate on SMTP server with username "laysosdeveloper@gmail.com" using 3 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8. Got this now – Emre Kd Oct 06 '22 at 07:26
  • It's nothing with the code. Its your username or password – Abdulla Nilam Oct 06 '22 at 07:27
  • @EmreKd check this as well https://stackoverflow.com/questions/42558903/expected-response-code-250-but-got-code-535-with-message-535-5-7-8-username – Abdulla Nilam Oct 06 '22 at 07:28
  • i can login gmail with this informations. – Emre Kd Oct 06 '22 at 07:29
  • Is 2 steps enabled in your Gmail? – Abdulla Nilam Oct 06 '22 at 07:29
  • No, its not enabled. – Emre Kd Oct 06 '22 at 07:31
  • click this and verify https://myaccount.google.com/lesssecureapps?pli=1&rapt=AEjHL4NzpdF6TBOzSanH-X1RmIRpLtVop8Tiyf9lNMuQfDgkPGZT6L2E8mBnFBke5_mQ6e21gBy_rQ407hdVCrlH6HUanpBbMg and if not enable the ***Less secure app access*** – Abdulla Nilam Oct 06 '22 at 07:31
  • it says "This setting is no longer available" – Emre Kd Oct 06 '22 at 07:32
  • @EmreKd it's there check this link https://www.itsolutionstuff.com/post/laravel-9-send-mail-using-gmail-smtp-serverexample.html. Just check with my alt account – Abdulla Nilam Oct 06 '22 at 07:35
  • 2
    Less Secure Apps was disabled in May 2022. Use an App Password instead- https://wpmailsmtp.com/gmail-less-secure-apps/ – ADyson Oct 06 '22 at 07:37
  • @ADyson for me it's still there https://gyazo.com/c80039b1a11e95c228fa7b48d32d92f6, or do both refer same? – Abdulla Nilam Oct 06 '22 at 07:39
  • thank you i generated a password and it worked. – Emre Kd Oct 06 '22 at 07:46
  • This setting is got removed by google i think. I cannot see it – Emre Kd Oct 06 '22 at 07:47
  • @EmreKd I sheard that link already https://stackoverflow.com/questions/73969812/how-can-i-send-emails-drirectly-to-users-with-laravel#comment130607163_73969905 – Abdulla Nilam Oct 06 '22 at 07:49
  • Sorry, ı am still learning to use stackoverflow, i edited the answer. Thank you for your help. – Emre Kd Oct 06 '22 at 07:55
  • @AbdullaNilam At a guess, maybe they are rolling this out gradually across the world and your location is not swiched over yet? Or possible you don't have 2-step verification enabled in your account. Either that, or if you try to actually turn on the feature, it won't work for SMTP, I would expect. I'm not sure, you'd have to ask Google for support if you wanted the exact answer. Here's the official article: https://support.google.com/accounts/answer/6010255 – ADyson Oct 06 '22 at 07:59
  • @ADyson, yeah, show the link that says ended. Anyway, Thanks for the valuable info. – Abdulla Nilam Oct 06 '22 at 08:01
1

I changed password and enabled 2-step verification.

  1. enable the 2-step verification to google

  2. Create App Password to be use by your system

I did those and it worked

Emre Kd
  • 27
  • 5
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 11 '22 at 08:21