If your Laravel script is not sending email, the problem is almost never one thing. It is usually a wrong port, a blocked port, a Gmail setting, or a config value that was never actually loaded. Work through the checks in order and you will find it in minutes.

We answer this question a lot, because almost every Laravel product needs to send email — password resets, order confirmations, invoices — and a silent mail failure makes the whole product look broken.

Is your mail config even loading?

Start here, because it is the most common cause and the easiest to miss. Laravel caches config, and a cached config ignores your .env changes completely. If you edited .env and nothing changed, run this from your project folder:

php artisan config:clear

Then check what Laravel actually sees, with:

php artisan tinker --execute="config('mail')"

If the output shows the old values, the config was cached. If it shows your new values, the problem is further down the chain. Also confirm the basics in .env: MAIL_MAILER=smtp, MAIL_HOST, MAIL_PORT, MAIL_USERNAME, MAIL_PASSWORD, MAIL_ENCRYPTION, and MAIL_FROM_ADDRESS. A typo in any one of these — an extra space, a missing letter in the host — is enough to stop everything.

One more check that saves a lot of time: confirm you are editing the .env file your site actually reads. On cPanel, the live project folder is usually public_html or a subfolder, and there may be an old copy of the project elsewhere. If in doubt, add a test value and run config:clear, then read it back with tinker.

Which port should you use: 587, 465 or 25?

Ports are where most SMTP setups die, because the right port depends on the encryption setting, and the two must match.

PortEncryptionHow it worksWhen to use it
587tlsStarts plain, then upgrades to TLSDefault choice for Gmail and most hosts
465sslEncrypted from the first byteWhen your host or provider requires it
25noneUnencryptedAlmost never; usually blocked on shared hosting

The rule is simple: port 587 goes with MAIL_ENCRYPTION=tls, and port 465 goes with MAIL_ENCRYPTION=ssl. Mixing them — 465 with tls, or 587 with ssl — is the single most common SMTP mistake we see, and it produces a connection timeout that tells you nothing useful.

Port 25 is a dead end on most shared hosts. Providers block it to stop spam, so even a correct setup will time out. If your config says port 25, change it before you debug anything else.

Is your host blocking the SMTP port?

Some shared hosts block outbound SMTP entirely, or block specific ports, and no amount of correct configuration will fix that. Before you blame your code, test whether the port is even reachable. From SSH or cPanel's terminal, run:

telnet smtp.gmail.com 587

If you get a connected response, the port is open and the problem is in your config. If it hangs or is refused, the host is blocking it, and you need to ask your hosting provider which outbound mail ports they allow — or switch to the mail service they recommend. Some hosts only allow their own mail server, which brings us to cPanel mail.

If you have no SSH or terminal access, you can test the same thing with a small PHP script that opens a socket to the host and port, or by asking your host's support team directly. Either way, do not skip this step: guessing at ports while the host blocks them wastes hours.

How do you set up Gmail SMTP in Laravel?

Gmail works well as a sender for small sites, but it has one rule that catches everyone: your normal Gmail password will not work. You need an app password, and that requires two-step verification on the Google account first.

Here is the order that works:

  • Turn on two-step verification for the Google account in your Google Account security settings.
  • Create an app password for Mail, and copy the 16-character code it shows you.
  • In .env, set MAIL_HOST=smtp.gmail.com, MAIL_PORT=587, MAIL_ENCRYPTION=tls, MAIL_USERNAME to your full Gmail address, and MAIL_PASSWORD to the app password — not your normal password.
  • Run php artisan config:clear, then send a test email.

If Gmail rejects the login, the usual causes are using the account password instead of the app password, or two-step verification not being on yet. Gmail's error messages will say authentication failed, which is accurate but unhelpful — check the password type first.

One honest warning: Gmail is a fine sender for a small site, but it is not a bulk mail service. If your product sends hundreds of emails a day, use a proper transactional mail service instead.

What about cPanel mail instead of Gmail?

cPanel mail is the other common choice, and it is often the simplest one on shared hosting because the mail server is on the same machine. Create an email account in cPanel, then use its settings: MAIL_HOST is usually mail.yourdomain.com, MAIL_PORT is 587 with tls (or 465 with ssl), MAIL_USERNAME is the full email address, and MAIL_PASSWORD is the password you set when creating the account.

The catch is deliverability. Mail sent from a shared host's IP can land in spam, especially if SPF and DKIM are not set up. In cPanel, check the Email Deliverability tool: it will tell you whether SPF and DKIM records exist for your domain and offer to fix them.

Also check that your domain's DNS actually points its MX records where you think. If your domain's email is handled by Google Workspace or another provider, cPanel mail will not receive replies — and if your script sends from an address that does not exist at the real provider, replies will bounce.

How do you test mail properly?

Do not test by waiting for a user to trigger a password reset. Use a route or a tinker command that sends one email on demand, and watch what happens. The fastest way is:

php artisan tinker --execute="Mail::raw('Test email', function ($m) { $m->to('you@example.com')->subject('Test'); });"

If it sends, your config works and the problem is in the feature that was supposed to trigger the email. If it throws an error, read the error message carefully — it names the failing step. A connection timeout means a port or host problem. An authentication error means wrong credentials.

And check the Laravel log, storage/logs/laravel.log, after every test. Mail errors are logged there with the full exception, including the exact SMTP conversation. That log entry is usually the whole answer.

If you are still stuck after these checks, the problem may be in the install itself rather than the mail settings. Our guide to 9 common errors after installing a Laravel script covers config cache, permissions and .env issues, and the cPanel installation guide walks through the full setup from scratch. You can also browse the full catalogue — every product ships with full unencrypted source code and an installation guide — and check the FAQs for the most common setup questions. If none of that unblocks you, our support is a real human on WhatsApp at +92 333 4916432, or by email at contact@zqdevelopers.com.