A contact form that looks finished is not the same as a contact form that works. I learned this on my own site: the form submitted cleanly, the thank-you message appeared, and no email ever arrived. The culprit was PHP mail() on shared hosting. If your form silently eats messages, this is probably what is happening, and SMTP is the fix.
What PHP mail() actually does
mail() does not send email. It hands a message to the local mail transfer agent, usually sendmail, and returns true if the handoff succeeded. That return value says nothing about delivery. The message can be dropped, rejected, or filed as spam after mail() has already told you everything is fine. That is the core problem: no delivery confirmation, no error from the receiving server, and nothing to debug with.
On a server you control, you can inspect the mail log and see what happened. On shared hosting, you usually cannot.
Why shared hosting breaks it
Shared hosts run hundreds of sites on one server, so they restrict outbound mail in ways that break mail():
- The sendmail binary may be disabled or restricted. Some hosts turn it off entirely. Your call returns false, or fails without a useful error.
- Messages go out from an unauthenticated sender.
mail()sends from an address likenobody@server.hostname, with no reputation and no authentication. Receiving servers treat that as a spam signal. - Strict rate limits apply. A host may cap outbound mail per hour per account. A small burst of form submissions can hit the cap and get silently dropped.
- SPF, DKIM, and DMARC fail. Modern mail providers check whether the sending server is allowed to send for your domain. A message sent through the shared server's local MTA usually fails those checks, so Gmail and Outlook file it as spam or reject it outright.
None of this is a bug in your code. It is the environment doing exactly what it was configured to do.
How to confirm mail() is the problem
Before changing anything, confirm where the failure is. Check that mail() exists and see which sendmail path PHP is using:
php -r "var_dump(function_exists('mail'));"
php -i | grep sendmail_path
Then send a test message to an address you control and check every folder, including spam, after a few minutes. If nothing arrives and there is no bounce, the message was likely dropped after the handoff. On shared hosting you generally cannot read the mail log to prove it, which is itself a reason to move on: a mail setup you cannot observe is a mail setup you cannot fix.
SMTP is the fix, not a workaround
SMTP sends mail through an authenticated mail server, using real credentials and your real domain. The receiving server sees a login it trusts, SPF and DKIM can pass, and failures come back as errors you can actually read. You also get a proper mail log from the SMTP provider instead of guessing.
In Laravel, it is a config change, not a rewrite. Set the mailer to SMTP in your .env file:
MAIL_MAILER=smtp
MAIL_HOST=smtp.example.com
MAIL_PORT=587
MAIL_USERNAME=you@example.com
MAIL_PASSWORD=your-app-password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=hello@example.com
MAIL_FROM_NAME="Your Name"
Replace the host and credentials with the ones from your mail provider. Port 587 with TLS is the standard choice for submitting mail. After changing the config, clear the cached config:
php artisan config:clear
Then send a real test message through the form, not just a test script. If it lands in the inbox, you are done. If it lands in spam, the next step is DNS: add the SPF record your provider gives you, and enable DKIM if supported. Authentication is what keeps your mail out of the spam folder, and it is the part mail() can never give you.
What to check before you ship a contact form
- Send from your own domain. The From address should match the domain the mail is authenticated for. A Gmail address in the From field, sent through another server, will fail DMARC on strict receivers.
- Use an app password or API key, never your main mailbox password. If the provider supports app passwords, use one, and keep it in
.env, never in version control. - Log mail failures. In Laravel, failed mail throws an exception you can log and alert on. A form that fails loudly beats one that fails silently.
- Test from the live server. Mail that works on your laptop can still fail on shared hosting if the host blocks outbound port 25 or 587. Test on the real server before you call the form done.
Takeaway
PHP mail() returning true means the message left your script. It does not mean anyone will read it. On shared hosting, unauthenticated local mail is dropped, rate-limited, or flagged as spam more often than it is delivered, and you get no log to tell you which one happened. Switch to authenticated SMTP, send from your own domain, and test on the live server. For the rest of the deployment checklist that caught this on my own site, see a deployment checklist for PHP sites on shared hosting.