Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expected response code 354 but got code "503"

Tags:

php

smtp

laravel

I am trying to create a Contact Us Form in a Laravel Project but ran into the following error and would like to know how to solve this.

Expected response code 354 but got code "503", with message "503-All RCPT commands were rejected with this error: 503-"Your IP: 202.133.88.147 : Your domain gmail.com is not allowed in header 503-From" 503 Valid RCPT command must precede DATA "

The following is my .ENV file

MAIL_DRIVER=smtp
MAIL_HOST=mail.mydomain.com
MAIL_PORT=26
[email protected]
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=null

Controller

  public function contactus()
    {
        return view('contactus');
    }

    public function sendContactMail(Request $request)
    {
        Mail::to('[email protected]')->send(new ContactUs($request));
        Session::flash('success','Message Sent Successfully!');
        return redirect()->back();
    }

ContactUs.php

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class ContactUs extends Mailable
{
    protected $contactdata;
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct(\Illuminate\Http\Request $request)
    {
        $this->contactdata = $request;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->from($this->contactdata->email)
                    ->subject($this->contactdata->subject)
                    ->with([
                        'message'   =>  $this->contactdata->message,
                        'fullname'  =>  $this->contactdata->first_name.' '.$this->contactdata->last_name
                    ])
                    ->markdown('emails.contactus');
    }
}

Thanks in advance for the help.

like image 373
I. Antonov Avatar asked Sep 19 '19 21:09

I. Antonov


Video Answer


3 Answers

I solved this by replacing Global "From" Address in mail.php file to the same input at .env for MAIL_USERNAME= .

like image 102
Emi Samad Avatar answered Oct 19 '22 18:10

Emi Samad


From the error message, you're probably sending email through Gmail's SMTP service.

Your .env should look like this:

MAIL_DRIVER=smtp
MAIL_HOST=mail.mydomain.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls

Also you need to make sure:

  1. Your domain mydomain.com is properly setup to use GSuite's Gmail. You cannot setup Gmail's SMTP to send email of domains that are not in GSuite nor is a Gmail account.

  2. If your account has 2-step-verificaton enabled, you'd need an App Password for SMTP login.

like image 4
Koala Yeung Avatar answered Oct 19 '22 18:10

Koala Yeung


In my case I fixed the issue by assigning MAIL_FROM_ADDRESS equal to MAIL_USERNAME. I don't know the explanation though.

MAIL_MAILER=smtp
MAIL_HOST=mail.domain.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl
[email protected]
like image 3
Makubex Avatar answered Oct 19 '22 19:10

Makubex