Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

When testing out our mail server we stumbled accross an error that prevents us from sending mails via PHP, though regular sending/receiving per Mail-in-a-box works without any problems. We are running a separate Ubuntu 18.04 server that only has Mail-in-a-box with all its needed components running.

Output in the error.log text file

PHP Fatal error: Uncaught Swift_TransportException: Expected response code 354 but got code "554", with message "554 5.5.1 Error: no valid recipients\r\n"

PHP file

$request_email = $_POST['request-email'];
$request_name = $_POST['request-name'];
$request_text = $_POST['request-text'];

$transport = (new Swift_SmtpTransport('data.abc.xy', 587, 'tls'))
    ->setUsername('[email protected]')
    ->setPassword('*******')
    ->setStreamOptions(array('ssl' => array('allow_self_signed' => true, 'verify_peer' => false)));

$mailer = (new Swift_Mailer($transport));

$message = (new Swift_Message('Name: '. $request_name))
    ->setFrom(['' . $request_email => '' . $request_name])
    ->setTo(['[email protected]'])
    ->setBody('E-Mail: ' . $request_email . $request_text)
    ->setContentType("text/html");

$result = $mailer->send($message);

What we have tried is to reinstall all of Mail-in-a-box and all of the components and checking everything for spelling mistakes. The ricipient does exist on our mail server and can receive and send mails manually via the client.

like image 750
Calendula Avatar asked Feb 10 '19 13:02

Calendula


People also ask

What is a 554 email error?

If you've received a 554 error message, you've been blocked from emailing the Comcast network because your email server is not properly identifying itself when connecting to our servers. This identification process is known as Reverse DNS.


2 Answers

I have solved this error (554) just adding to laravel (.env file) these 2 lines:

[email protected]
MAIL_FROM_NAME="[email protected]"

Finally, run this command to flush mail cache config:

php artisan config:cache
like image 158
gtamborero Avatar answered Oct 14 '22 15:10

gtamborero


The 554 5.5.1 error is the SMTP error "no valid recipients". It can occur if you've misspelled the recipient addresses but it can also occur if you are not properly authenticating to the outgoing server.

So the problem is that abc.xy is not a registered domain so you can't send an email to this address. I think it's not something related to your code.

You can catch the Swift_TransportException error and handle it in your own codebase like :

try {
    $result = $mailer->send($message);
} 
catch (Swift_TransportException $e) {
    echo $e->getMessage();
}
like image 11
Amine KOUIS Avatar answered Oct 14 '22 14:10

Amine KOUIS