How do we solve error 554 5.5.1 (no valid recipients) when using PHP Swiftmailer?

How do we solve error 554 5.5.1 (no valid recipients) when using PHP Swiftmailer?

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Decoding Swiftmailer Error 554 5.5.1: No Valid Recipients

When debugging mail delivery issues with PHP and Swiftmailer, a Swift_TransportException reporting "Expected response code 354 but got code '554'" often points to a specific SMTP handshake failure. The accompanying message, "554 5.5.1 Error: no valid recipients," indicates that the remote server rejected the recipient address before accepting the mail data or even acknowledging the sender's identity.

In the scenario described by the user running Mail-in-a-box on Ubuntu 18.04, standard mail flow via a client works perfectly, yet the PHP application fails. This discrepancy suggests the issue isn't with the underlying mail server's ability to deliver mail globally, but rather how the connection is being established or authenticated during the SMTP transaction initiated by the script.

The root cause of error 5.5.1 in this context usually stems from one of three areas: insufficient authentication before issuing the RCPT TO command, the use of an invalid email format that the server rejects as "unverified," or a strict relay restriction preventing external addresses from being accepted without proper credentials.

Authentication Handshake Order

The provided PHP code snippet sets up a connection to data.abc.xy on port 587 with TLS. However, there is a critical logical gap in how the SMTP protocol is being handled here relative to the server's configuration. Many modern mail servers, including those configured by Mail-in-a-box, enforce strict security policies that require authentication before the client can specify any recipients.

The error "no valid recipients" often appears when the server interprets an unauthenticated RCPT TO command as a request for open relay usage. If the remote server expects the client to authenticate first (via AUTH LOGIN), and the script sends RCPT TO immediately after connecting, the server will reject the recipient address because it has no reason to trust the source yet.

To resolve this, the Swiftmailer transport configuration must ensure that authentication is attempted before sending the email body or recipients. While Swiftmailer handles the SMTP sequence internally, the underlying logic relies on the Swift_SmtpTransport initiating the session correctly. If the server requires SASL authentication prior to any data transfer, the script must be verified to not send recipients until the handshake is complete.

Address Format and Validation

Another frequent culprit for 5.5.1 errors is the format of the email address used in the setTo method. The source code shows:

->setFrom(['' . $request_email => '' . $request_name])
->setTo(['contact@abc.xy'])

If $request_email contains whitespace, special characters, or is empty (due to a missing POST value), the resulting string might not conform to RFC 5322 standards. Some strict mail servers will reject such addresses immediately with a "no valid recipients" error because they cannot parse the local part or domain structure correctly.

Ensure that $request_email is strictly validated before being passed to Swiftmailer. Trimming whitespace and ensuring it contains exactly one @ symbol are essential steps. If the server receives an address like user@example.com (with a leading space) or user @example.com, the remote MTA might reject it before processing the content.

Debugging the SMTP Stream

To pinpoint exactly where the failure occurs, you need to inspect the raw SMTP conversation. Swiftmailer provides a mechanism to log these interactions. By enabling debug output on the transport layer, you can see if the AUTH command is being sent and acknowledged before the RCPT TO command.

Add the following configuration to your transport setup:

$transport->setDebugOutput('swift_debug.log');

Reviewing this log will reveal whether the server responds with a 535 error (Authentication failed) or a 501/554 error regarding recipients. If authentication is failing silently or not happening at all, the server assumes the client is untrusted and blocks recipient delivery.

Additionally, check the verify_peer setting in your stream options. The code sets verify_peer to false. While this allows connections to self-signed certificates, some servers inspect the certificate chain strictly. If the TLS handshake fails or returns an unexpected state, the application might proceed with a malformed session, leading to ambiguous error codes from the server.

Conclusion

The "no valid recipients" error in this setup is rarely about the recipient address actually existing on the mail server. Since manual sending works, the issue lies in the interaction protocol: likely a missing authentication step before recipient declaration or an invalid email format string being transmitted. By validating input strings rigorously and ensuring the SMTP handshake includes successful authentication before addressing recipients, the 5.5.1 error can be resolved.

Our network