Reputation: 191
Note: this sadly is no duplicate, I already tried everything mentioned there.
I tried to set up a connection to my mailserver with Laravel/Swiftmailer
. The Mailing section of my .env looks as follows:
MAIL_DRIVER=smtp
MAIL_HOST=<THE MAILHOST>
MAIL_PORT=465
MAIL_USERNAME=<THE USERNAME>
MAIL_PASSWORD=<THE PASSWORD>
MAIL_ENCRYPTION=ssl
Personal information is censored for obvious reasons, but the configuration does work. I tested it by connecting to the server with this configuration with thunderbird and it works like a charm.
Here is where I call the Mailable:
public function from_id(string $id): User
{
.
.
.
Mail::to(<WORKING EMAIL ADRESS>)->send(new OrderShipped());
}
Thats how the Mailable looks like (it basically is the example one from the laravel docs):
public function build()
{
return $this->view('email_templates.simple_test');
}
I debugged into the code and there are actually two exceptions thrown, altough whoops! only shows the latter:
Expected response code 250/251/252 but got code "554", with message "554 5.7.1 : Recipient address rejected: Access denied"
Expected response code 354 but got code "554", with message "554 5.5.1 Error: no valid recipients"
I tried to sent an email from the perfectly working mailserver via thunderbird to the <WORKING EMAIL ADRESS>
and the mail got sent and received in a fraction of a second and without any problems/errors. Basically, I tried to reproduce the exact same scenario with a different tool. So from my point of view, the error must be in the codebase.
Thanks in advance
Upvotes: 3
Views: 12905
Reputation: 175
My answer isn't Laravel specific, as I'm working in Yii2 environment, but the error message was the same as above. (Maybe I'll help someone someday.)
My original problem: the contact form was not working while at other places the app was sending out automatic mails properly - which was weird.
It turned out that when setting the 'from address' in the SwiftMailer config I put in the contacting person's (sender's) e-mail address, which was not allowed.
When I configured the proper user account (which I use to authenticate to the SMTP server) as the sender address, there was no issue. As soon as I tried to 'mimic' that the users are sending the e-mails from their own addresses, I was given that same message.
All I could do to "fix" this is to include the 'ReplyTo' parameter with the e-mail, this way when I reply to the incoming mail in Outlook, the actual sender's address is populated instead of the SMTP mailbox used for contact-mail-sending.
I've also included a short message at the bottom of the Body to indicate who the sender is (name and address) - just for convenience.
Upvotes: 1
Reputation: 400
Your setup looks a little strange to me. Please try with the below syntax (note here I've included a $_orderObject
variable as a placeholder to represent order details):
app/Mail/OrderShipped.php
<?php
namespace App\Mail;
use Illuminate\Mail\Mailable;
class OrderShipped extends Mailable
{
protected $_name;
protected $_orderObject;
public function __construct($name, $order)
{
$this->_name = $name;
$this->_orderObject = $order
}
public function build ()
{
return $this->to (<CONFIRMED WORKING EMAIL>)
->subject ('New Order!')
->view ('email_templates.simple_test')
->with ([
'name' => $this->_name,
'order' => $this->_orderObject
]);
}
}
//calling it
public function from_id(string $id): User
{
$name = << $this->getUserNameById ($id) >> // fake method
$orderObject = << $this->getLatestOrderByUserId($id) >> // fake method
Mail::send(new OrderShipped($name, $orderObject));
}
Upvotes: 0
Reputation: 728
You need to contact your sysadmin to ask if you need STARTTLS or just TLS.
STARTTLS starts a plain connection and then switches to a secure TLS 'channel', TLS connects to secure connection directly but is less compatible.
if the answer is STARTTLS use the port 587 else keep your port but verify it with your sysadmin
another reason could be that you account was banned or your IP blocked
Upvotes: 1
Reputation: 2321
This seems to be a SMTP error, what kind of error code you are getting ?
Code 354: means the SMTP server telling Laravel to proceed and send the body of the email. Note that this is what is expected, and not what you received.
Code 554: from a SMTP server indicates: "Transaction Failed", and you'll note that this is what you actually got.
The reason this is failing is indicated further in the message: "Error: no valid recipients."
Without further data it will be hard to tell why the recipient isn't set properly on your codebase.
For complete list of smtp erro codes can visit: https://sendgrid.com/blog/smtp-server-response-codes-explained/
Upvotes: 3