Expected response code 354 but got code "503"
You are encountering a classic SMTP handshake failure where the mail server is rejecting your transaction before you can even attempt to send data. The error message Expected response code 354 but got code "503" indicates that the sending server (your application) sent a DATA command expecting permission to transmit the email body, but the receiving SMTP server responded with 503.
The specific rejection reason reveals the root cause: Your IP: 202.133.88.147 : Your domain gmail.com is not allowed in header 503-From. This is a strict anti-spam measure enforced by the receiving mail server, often a shared hosting provider or an enterprise gateway. They are blocking the MAIL FROM address because it claims to originate from gmail.com, which is not associated with your sending IP address.
Misconfigured Sender Identity
In your ContactUs.php mailable class, you are dynamically setting the sender using the user's input:
public function build()
{
return $this->from($this->contactdata->email)
->subject($this->contactdata->subject)
// ...
}
This approach is fundamentally flawed for two reasons. First, you are trusting the client to provide a valid email address in the From header. If a user enters support@mydomain.com, it works fine. However, if a user enters their own Gmail address (user@gmail.com) or any other domain, and your application sends an email claiming to be from that Gmail address but originates from your shared hosting IP (202.133.88.147), the receiving server sees a mismatch.
Second, and more critically, you are using MAIL_HOST=mail.mydomain.com with MAIL_PORT=26. Port 26 is exclusively used for Submission, typically requiring authentication via SASL. Standard SMTP transactions (where the server accepts the connection without auth first) usually occur on port 25 or 587. Furthermore, you have set MAIL_ENCRYPTION=null. Most modern SMTP providers require TLS encryption (tls or ssl) to prevent credentials from being intercepted in cleartext, especially when sending as a non-secure submission client.
The Shared IP Problem
The error explicitly flags your IP: 202.133.88.147. This is almost certainly a shared hosting IP address. Because multiple websites share this single IP, the receiving mail server treats all emails sent from this IP with high suspicion. When an email arrives claiming to be from gmail.com but coming from a known shared hosting IP used by unrelated domains, it triggers spam filters and reputation blacklists immediately.
The error message Your domain gmail.com is not allowed in header 503-From confirms the server expects the MAIL FROM address to match your domain or a verified source. You cannot simply ask an email server to "pretend" to be from Gmail; that would be spoofing. The receiving server enforces SPF (Sender Policy Framework) and DKIM checks, which will fail in this scenario because the DNS records for gmail.com do not authorize the IP 202.133.88.147 to send mail on their behalf.
Correct Implementation Strategy
To resolve this, you must stop attempting to use the user's email address as the From header sender. The From address should be a verified identity associated with your domain.
Update your .ENV file to use a standard secure port and encryption:
MAIL_DRIVER=smtp
MAIL_HOST=mail.mydomain.com
MAIL_PORT=587
MAIL_USERNAME=support@mydomain.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=support@mydomain.com
MAIL_FROM_NAME="${APP_NAME}"
Then, modify your ContactUs mailable to use the configured sender from the environment rather than the user's input for the From header:
public function build()
{
return $this->from(config('mail.from.address'), config('mail.from.name'))
->subject($this->contactdata->subject)
->to($this->contactdata->email) // User's email goes in the To field
->view('emails.contactus')
->with([
'message' => $this->contactdata->message,
'fullname' => $this->contactdata->first_name . ' ' . $this->contactdata->last_name
]);
}
By setting the From address to a legitimate domain (e.g., support@mydomain.com) and sending the user's email in the To or Reply-To field, you align with SMTP standards. This ensures the IP 202.133.88.147 is authorized to send mail for your domain, satisfying the receiving server's checks.
Additional Considerations
If mail.mydomain.com resolves to the same shared IP as your website (202.133.88.147), you must configure SPF records in your DNS to explicitly allow this IP to send mail for your domain. Without a proper SPF record pointing to the mail server, legitimate emails will be marked as spam or rejected outright by major providers like Gmail and Outlook.
For higher volume applications or if you require guaranteed delivery without shared IP restrictions, consider switching to a dedicated transactional email provider like Amazon SES, Mailgun, or SendGrid. These services provide dedicated IPs with excellent reputation scores and handle the complex DNS configurations (SPF, DKIM, DMARC) automatically. Tools from LaravelCompany can help you integrate these providers seamlessly into your stack if you decide to migrate away from shared SMTP hosting.
Finally, ensure that your application does not queue messages unless explicitly configured. The Queueable trait in your mailable suggests you might be using the queue driver, but if your queue worker is running on a different server or if the job fails silently, you may not see immediate feedback. For a contact form, synchronous sending is often preferred to provide instant user feedback via the Session::flash redirect.