I’m trying to send emails using Gmail’s SMTP server but running into an issue with the sender address. When I set up my email to be sent from a custom address, the recipient still sees it coming from my Gmail account instead.
I want the email to show as coming from [email protected] but it keeps showing my Gmail address instead. Is there a way to override the sender address when using Gmail’s SMTP server? What am I missing in my configuration?
This isn’t a PHP problem - it’s Gmail blocking you. Gmail automatically swaps out the From header with your authenticated account email to stop spoofing attempts. Here’s the fix: go to your Gmail settings, then Accounts and Import > Send mail as. Add your [email protected] address there. Gmail will make you verify it first, but once that’s done, you can use that address in the From field.
You’re running into Gmail’s security policy - it blocks arbitrary sender addresses. Even with proper SMTP authentication, Gmail rewrites the From header to match your authenticated account unless you’ve pre-authorized the custom address. That verification process is crucial. Without it, Gmail flags any custom From address as potential spam or phishing. Some email clients might still show your Gmail address in certain views even after you set everything up correctly. If this is for business, skip Gmail SMTP and use something like SendGrid or Mailgun instead. They’re built for this kind of customization without all the restrictions.