Reputation: 47
I want to send email to outlook
in laravel 5.6
.env file
MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=******
MAIL_PASSWORD="******"
MAIL_ENCRYPTION=tls
config/mail.php
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.office365.com'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
'name' => env('MAIL_FROM_NAME', 'Kishor Bhatt'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
email/mail.blade.php
<h3>You have received new email.</h3>
<div>
<b>Name:</b> {{ $name }} <br>
<b>Email:</b> {{ $email }} <br>
<b>Phone No:</b> {{ $phone }} <br>
<div>
<b>Message:</b> {{ $bodyMessage }}
</div>
</div>
<p> Send By: {{ $email }} <p>
sendmail() function
$data = $request->all();
$mail = array(
'name' => $data['name'],
'phone' => $data['phone'],
'email' => $data['email'],
'bodyMessage' => $data['message']
);
Mail::send('email.mail', $mail, function($message) use ($mail){
$message->from($mail['email']);
$message->to('[email protected]');
$message->subject('Query from '.$mail['name']);
});
return redirect('/contact-us')->with('flash_message_success','Thank you for your feedback. We will get back shortly.');
Error:
Failed to authenticate on SMTP server with username "[email protected]" using 2 possible authenticators. Authenticator LOGIN returned Swift_TransportException: Expected response code 235 but got code "535", with message "535 5.7.3 Authentication unsuccessful.
How do I solve the error and send the email to outlook?
Upvotes: 0
Views: 8202
Reputation: 19
I had the same problem in laravel 5.8 with an exchange server. I solved this by doing this in the .env
MAIL_DRIVER=smtp
MAIL_HOST=ipadress
MAIL_PORT=587
MAIL_USERNAME="*******"
MAIL_PASSWORD="********"
MAIL_ENCRYPTION=''
Upvotes: 1