Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ben123456's avatar

Cannot send email from website using mail server

Hello, I am in much need of help on a problem that I have not been able to work past in nearly a week.

I have currently setup two servers. One a mail server and the other to host my site.

The issue I am facing is that my contact form on my website cannot send emails. Trying to do so you get the error from laravel:

Expected response code 354 but got code "554", with message "554 5.5.1 Error: no valid recipients "

The error indicates that the address I am emailing is not valid, but it is and I have had this working using the live mail server, on my local machine. I have even changed the recipient to a working gmail account to be sure. I am 99% sure that the laravel site is set up correctly.

What is interesting is that I get a different errors from postfix on the mail server side. Here are the four logs that are generated from request to send mail.

Oct 23 22:52:07 compute-it postfix/submission/smtpd[1417]: connect from li1525-157.members.linode.com[139.162.240.157]

Oct 23 22:52:07 compute-it postfix/submission/smtpd[1417]: Anonymous TLS connection established from li1525-157.members.linode.com[139.162.240.157]: TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)

Oct 23 22:52:07 compute-it postfix/submission/smtpd[1417]: NOQUEUE: reject: RCPT from li1525-157.members.linode.com[139.162.240.157]: 554 5.7.1 <li1525-157.members.linode.com[139.162.240.157]>: Client host rejected: Access denied; from=<[email protected]> to=<[email protected]> proto=ESMTP helo=<compute-it.org.uk>

Oct 23 22:52:07 compute-it postfix/submission/smtpd[1417]: disconnect from li1525-157.members.linode.com[139.162.240.157] ehlo=2 starttls=1 mail=1 rcpt=0/1 data=0/1 quit=1 commands=5/7

Any ideas? I seriously have gone everywhere and tried everything I can think of. to be clear: port 587 is open on both The mail server works i.e. I can send and receive mails. The website sends mail to the mail server using the mail server when ran on my local machine. The to and from address are valid and working.

0 likes
8 replies
ahmeddabak's avatar

please paste the code you are using to send the email

ben123456's avatar

To be clear: I am using my [email protected] to send email to [email protected]

Controller that sends email

Mail::to('[email protected]')->send(new InquiryEmail($data));

InquiryEmail class

public function __construct($data)
{
    $this->data = $data;
}

public function build()
{
    return $this->from('[email protected]')
        // inquiry is a html email that gets built out of data variable
        ->view('inquiry')
        ->with([
            'data' => $this->data
        ]);
}

.env snippet

MAIL_DRIVER=smtp
MAIL_HOST=mail.compute-it.org.uk
MAIL_PORT="587"
[email protected]
MAIL_PASSWORD=***********
MAIL_ENCRYPTION=tls

mail.php (think this is used over my .env

return [
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'mail.compute-it.org.uk'),
    'port' => env('MAIL_PORT', 587),  
    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
        'name' => env('MAIL_FROM_NAME', 'webserver'),
    ],
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),   
    'username' => env('[email protected]'),
    'password' => env('***********'),
    'sendmail' => '/usr/sbin/sendmail -bs',    
    'markdown' => [
        'theme' => 'default',
        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],
    'log_channel' => env('MAIL_LOG_CHANNEL'),

];
ben123456's avatar

Any help anyone could give would be great. I am no closer to resolving this.

siangboon's avatar

Client host rejected: Access denied

look like you are not allow to send

if your password has # or special character you need to quote it

MAIL_PASSWORD='strong#password'
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

The problem is here. You are looking for env variables by value, not key

'username' => env('[email protected]'),
    'password' => env('***********'),

Should be


'username' => env(MAIL_USERNAME),
    'password' => env(MAIL_PASSWORD),
2 likes
ben123456's avatar

@sinnbeck I could honestly kiss you, Thanks. I have had bad tunnel vision on this problem. Clearly. As my error was in front of me. Again, thanks for the help.

One thing I do not get is why did this work on my local machine?

Sinnbeck's avatar

Perhaps your config was cached with the correct setup? Remember to mark best answer if it was solved :)

ben123456's avatar

@sinnbeck "Perhaps your config was cached with the correct setup? " that must have been it as I did not do a cache clear when I ran it locally so those setting would never have been updated.

Please or to participate in this conversation.