Laravel send mail via Gmail fails - cannot connect to server - laravel

The server, Ubuntu 16.04, with Nginx webserver.
I am running 2 virtual hosts, both have Laravel apps running. One is Laravel 5.1, the other is 5.4.
I have the same contact us form under both Laravel instances. The sendmail function on the controller is the same for both (I know I need to refactor this functionality off of the controller :-) ) Both have the same config/mail.php settings. .env is the same on both, other than the username and password. Both gmail accounts have insecure applications enabled / allowed.
The one running under Laravel 5.1 works perfectly. The one under 5.4 gives a timeout error when trying to connect to gmail.
Any ideas on what the fix should be?

The solution appears to be related to the Gmail password. The client insisted on an easily remembered password. I changed to a more complex password, and everything worked.
I did read a post that said that Google does not like automated accesses with insecure passwords. Sorry, I cannot reference that post - can't find it again.
Apparently, the solution is to use a secure password. I merely added special characters to the client's desired password.
I hope this helps someone else.

Related

How to properly configure Laravel mail in Heroku? [duplicate]

I'm currently having trouble with the password reset mail created by make:auth in Laravel 5.6. My app is hosted on Heroku. In my local environment everything works fine. I have set the right values in the config vars in Heroku, same in my local .env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myMail#gmail.com
MAIL_PASSWORD=bla
MAIL_ENCRYPTION=tls
I have read here that I have to hard-code the values inside app/mail.php instead of referencing the .env file because Heroku wouldn't recognize/understand this reference
'password' => env('MAIL_PASSWORD')
But then my data would be visible inside the GitHub repo.
What am I doing wrong here?
EDIT:
The accepted answer is the way to go, one should use an Add-On for sending mails in Heroku. Still I found a way to make it work with gmail after setting up sendgrid ;)
- Use `Port 465 with ssl` as encryption.
- Allow `less secure apps` access to my account.
- Visit `http://www.google.com/accounts/DisplayUnlockCaptcha` and sign in with your Gmail username and password.
After these steps, it worked.
Maybe this is helpful for others.
EDIT2:
I migrated Laravel from version 5.x to 8 and I ran into problems again, so I had to change my approach again with gmail.
I had to:
- Allow `less secure apps` access to my account.
- Enable two step verification and create an App Password like in the accepted answer of this question: https://stackoverflow.com/questions/42558903/expected-response-code-250-but-got-code-535-with-message-535-5-7-8-username
- Change Port back to 587 and tls again
- Visit `http://www.google.com/accounts/DisplayUnlockCaptcha` and sign in with your Gmail username and password.
Don't use Gmail in production¹.
Gmail isn't designed to act as an SMTP gateway for your application. Instead, use one of the many mail addons that Heroku recommends. Mailgun and SendGrid are both very popular options, but there are lots of others.
These tools are designed to send mail for applications. They'll be a lot less likely to reject your mail and, when configured properly, make it a lot less likely for your mail to get caught in spam filters. Most of them have walkthroughs for setting things up, and I encourage you to follow them. Make sure not to skip the SPF and DKIM anti-spam features.
I have read here that I have to hard-code the values inside app/mail.php instead of referencing the .env file because Heroku wouldn't recognize/understand this reference
'password' => env('MAIL_PASSWORD')
This is incorrect.
You say that you've set config variables on Heroku, and that populates the environment. The .env file is just a convenient local workaround for doing the same thing. Whichever mail addon you choose will automatically set one or more environment variables for you, and you should use those in your code.
¹You probably shouldn't be using it in development, either, but it's less of a problem there. I urge you to use something like Mailtrap (cloud) or Mailcatcher (local) instead.

Laravel Fortify Email Verification failing

I am using Laravel 8 with Fortify.
Everything is working Fine so far apart from email verification.
The Issue
When a user registers successfully they receive an email containing a signed url.
When the url is clicked, the user is redirected to the login page.
The user signs in.
verified_at field in db is not updated
Here is a generated link from the email
https://certhub.test/email/verify/1/7c9f29d87b505da773415b7e0369368e6eaf5fa6?expires=1643801371&signature=a255a0f05fcdb9a23cb7dba392e39317db3cd6657b69d7799c4840008d1633e0
Has anyone experienced this issue?
I spent a good 2 days to fix mine and my problem was I had 'same_site' set to strict in my sessions.php and changing to lax did the job for me.

Synchronizing laravel app password with Active Directory

We have gotten a request to synchronize the passwords for a SaaS app our company produces with Active Directory for a customer.
I have straight up never even touched AD, so I have no idea where to even begin, or if it's possible.
The App is laravel 5.2 + php5.6 and not running on Azure.
Any guidance would be extremely appreciated. Please ask if you need more information, I don't even have much of an idea of what would be relevant to know here.
Thanks for anything you can give me in advance, guys.
There is no way to read anyone's password from Active Directoy, so you cannot "synchronize" passwords.
However, you could just authenticate against AD (when someone tries to log into your app, your app sends their username and password to AD to verify). There is an answer for how to do that here, but it's literally just this:
$ldap = ldap_connect("ldap.example.com");
if ($bind = ldap_bind($ldap, $_POST['username'], $_POST['password'])) {
// log them in!
} else {
// error message
}
Where ldap.example.com will be the AD domain name. The default is port 389, so that communication has to be allowed by firewall. If they want the traffic to be encrypted via SSL (LDAPS), then it would be over port 636 and you have to specify that:
$ldap = ldap_connect("ldap.example.com", 636);
And you would need to trust their certificate. Details on that in the comments of the documentation for ldap_connect.

Laravel password reset email not sending using gmail on Heroku

I'm currently having trouble with the password reset mail created by make:auth in Laravel 5.6. My app is hosted on Heroku. In my local environment everything works fine. I have set the right values in the config vars in Heroku, same in my local .env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myMail#gmail.com
MAIL_PASSWORD=bla
MAIL_ENCRYPTION=tls
I have read here that I have to hard-code the values inside app/mail.php instead of referencing the .env file because Heroku wouldn't recognize/understand this reference
'password' => env('MAIL_PASSWORD')
But then my data would be visible inside the GitHub repo.
What am I doing wrong here?
EDIT:
The accepted answer is the way to go, one should use an Add-On for sending mails in Heroku. Still I found a way to make it work with gmail after setting up sendgrid ;)
- Use `Port 465 with ssl` as encryption.
- Allow `less secure apps` access to my account.
- Visit `http://www.google.com/accounts/DisplayUnlockCaptcha` and sign in with your Gmail username and password.
After these steps, it worked.
Maybe this is helpful for others.
EDIT2:
I migrated Laravel from version 5.x to 8 and I ran into problems again, so I had to change my approach again with gmail.
I had to:
- Allow `less secure apps` access to my account.
- Enable two step verification and create an App Password like in the accepted answer of this question: https://stackoverflow.com/questions/42558903/expected-response-code-250-but-got-code-535-with-message-535-5-7-8-username
- Change Port back to 587 and tls again
- Visit `http://www.google.com/accounts/DisplayUnlockCaptcha` and sign in with your Gmail username and password.
Don't use Gmail in production¹.
Gmail isn't designed to act as an SMTP gateway for your application. Instead, use one of the many mail addons that Heroku recommends. Mailgun and SendGrid are both very popular options, but there are lots of others.
These tools are designed to send mail for applications. They'll be a lot less likely to reject your mail and, when configured properly, make it a lot less likely for your mail to get caught in spam filters. Most of them have walkthroughs for setting things up, and I encourage you to follow them. Make sure not to skip the SPF and DKIM anti-spam features.
I have read here that I have to hard-code the values inside app/mail.php instead of referencing the .env file because Heroku wouldn't recognize/understand this reference
'password' => env('MAIL_PASSWORD')
This is incorrect.
You say that you've set config variables on Heroku, and that populates the environment. The .env file is just a convenient local workaround for doing the same thing. Whichever mail addon you choose will automatically set one or more environment variables for you, and you should use those in your code.
¹You probably shouldn't be using it in development, either, but it's less of a problem there. I urge you to use something like Mailtrap (cloud) or Mailcatcher (local) instead.

My magento site can't sent email to the customer

Does anyone know why Magento 1.4 fails to send email notifications for a new order and account activation ?
when I submit the Contact us form it gives the below error.
Unable to submit your request. Please, try again laterAny idea/suggestion on this will be highly appreciated.
More info please. Is this on a Linux box, Windows, etc... Also check the php configuration SMTP settings. Like any php app, email is handed off to the host system, or to server designated in php.ini. Do you have a known working SMTP server to access?
First thing you need to check is whether email communication is disabled in the admin panel.

Resources