doudizhi947129 2019-02-05 07:44
浏览 197

如何向laravel 5.6中的outlook发送电子邮件?

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', 'kishor.bhatt@cdscnp.com'),
    '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('shankar.bhatt@cdscnp.com');
            $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 "prem.basnet@cdscnp.com" 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?

  • 写回答

1条回答 默认 最新

  • dqfaom241360 2019-07-15 11:38
    关注

    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=''
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog