I am trying to send a mail through my contact from and i am getting this error:
Swift_TransportException (550) Expected response code 250 but got code "550", with message "550-Your FROM address ( [email protected] , [email protected] ) must match your 550-authenticated email user ( [email protected] ). Treating this as a spoofed 550 email. "
My .ENV config:
MAIL_HOST=mail.exemple.ro
MAIL_PORT=465
MAIL_ENCRYPTION=ssl
MAIL_PASSWORD=my pass
[email protected]
MAIL_DRIVER=smtp
[email protected]
My Contoller:
{
$validator = Validator::make($request->all(), [
'firstName' => 'required',
'lastName' => 'required',
'email' => 'required',
'services' => 'required',
'message' => 'required',
]);
if ($validator->fails()) {
return redirect('en/404')
->withErrors($validator)
->withInput();
}
$form = $request->all();
$message->success('The message was successfully send!');
Mail::send('email/contact-form', compact('form'), function ($email_message) use ($form) {
$email_message->subject($form['services']);
$email_message->from($form['email']);
$email_message->to('[email protected]');
});
return back();
}
If i try to write the input Email with [email protected] i get no error but when i try to enter a gmail or other email i am getting the error above.
Please help!
You messed your code here
Just replace code from
Mail::send('email/contact-form', compact('form'), function ($email_message) use ($form) {
$email_message->subject($form['services']);
$email_message->from($form['email']);
$email_message->to('[email protected]');
});
To this below one
Mail::send('email/contact-form', compact('form'), function ($email_message) use ($form) {
$email_message->subject($form['services']);
$email_message->from(env('MAIL_USERNAME'),$form['email']);
$email_message->to(env('MAIL_USERNAME'));
});
You were messing code in from and to. As you can only enter email in from which can authenticate to your MAIL_HOST server on port MAIL_PORT, thats why you don't get any error when you enter your email address.
I hope this would help you.