I
I
Ilbiondo2018-01-10 17:25:33
SMTP
Ilbiondo, 2018-01-10 17:25:33

How to set up sending emails via SMTP in laravel 5.5?

Good afternoon!
I'm trying to submit a form to a specific mailbox, I'm getting the error: "Address in mailbox given [] does not comply with RFC 2822, 3.6.2". As I understand it, this is a reference to SERVER_ADMIN = "[no address given]", but I don't understand why the server address is not set (and where should it be set)?
.env :

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mail.ru
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=mypass
MAIL_ENCRYPTION=ssl

Controller:
use Mail;

public function execute(Request $request){
     if($request->isMethod('post')){
        $messages = [
          'required' => "Field :attribute is required",
          'email' => "Field :attribute must be an email"  
        ];
        $this->validate($request, [
            'name' => 'required|max:255',
            'email' => 'required|email',
            'text' => 'required'
        ], $messages);
        $data = $request->all();
        $result = Mail::send('site.email', ['data'=>$data], function($message) use ($data){  
           $mail_admin = env('MAIL_USERNAME');
           $message->from($data['email'], $data['name']);
           $message->to($mail_admin, 'To me')->subject('Request');
        });
        if($result){
           return redirect()->route('home')->with('status', 'Email is sent');
        }              
     }

The documentation for version 5.5 says that you need to use the to method of the Mail facade instead of the send
method
.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Antonio Solo, 2018-01-10
@Ilbiondo

1) the FROM field must match MAIL_USERNAME
2) the TO field must be set and valid
3) just in case, check what you have in config/mail.php

P
Pavel, 2019-05-06
Sayk @PiSaiK

It was very vague. Works it is necessary to configure Gmail itself. Instruction

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question