Answer the question
In order to leave comments, you need to log in
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
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');
}
}
Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question