Seeker1337
6 months ago
922
2
Laravel

Laravel 6+ Contact form send email error #535

Posted 6 months ago by Seeker1337

Hey there. I have a Contact form in my website containing Email, Subject and content fields. However, when I click on 'Send message' I get the following error:

Failed to authenticate on SMTP server with username "myusername" using 3 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "535", with message "535-5.7.8 Username and Password not accepted.

EDIT: I have a Google Authenticator enabled for that email address.

Here are my files:

web.php

use Illuminate\Http\Request;
use App\Mail\ContactsMail;
use Illuminate\Support\Facades\Mail;

Route::get('/contacts', function() {
    
    return view('contacts') ;
    
}) ;

Route::post('/contacts', function(Request $request) {
    
    Mail::send(new ContactsMail($request)) ;
    return redirect('/') ;
    
}) ;

ContactsMail.php

namespace App\Mail;

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

class ContactsMail extends Mailable
{
    use Queueable, SerializesModels;

    public $email ;
    
    public function __construct(Request $request) {
        
        $this->email = $request ;
    }

    
    /**
     * Build the message.
     *
     * @return $this
     */
    public function build() {
        
        return $this->subject('New Contact Mail') 
                    ->from('[email protected]') 
                    ->to('[email protected]') 
                    ->view('emails.contacts-message') ;
        // Im not generating what's put through the contact form just because I wanted to test this out. Can this be the problem?
   }
       
}


emails folder -> contacts-message.blade.php

{{ $email->content }}

contacts.blade.php

<form action="{{ url('/contacts') }}" method="post">
@CSRF

<div class="form-group">
<label>Email</label>
<input type="email" name="email" class="form-control">
</div>

<div class="form-group">
<label>Subject</label>
<input type="subject" name="subject" class="form-control">
</div>

<div class="form-group">
<label>Message</label>
<textarea  name="content" class="form-control"></textarea>
</div>

<button type="submit" class="btn btn-primary"> Submit </button>
</form>

.env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl

Please sign in or create an account to participate in this conversation.