如何在laravel 5.6中向Outlook发送电子邮件?

时间:2019-02-05 07:44:15

标签: php laravel laravel-5

我想向outlook中的laravel 5.6发送电子邮件

.env文件

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()函数

    $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.');

错误:

  

无法使用用户名在SMTP服务器上进行身份验证   “ prem.basnet@cdscnp.com”使用2个可能的身份验证器。   身份验证器LOGIN返回Swift_TransportException:预期   响应代码235,但得到的代码为“ 535”,消息为“ 535 5.7.3”   身份验证失败。

如何解决错误并将电子邮件发送到Outlook?

1 个答案:

答案 0 :(得分:0)

在带有交换服务器的laravel 5.8中,我遇到了同样的问题。 我通过在.env

中执行此操作解决了此问题
MAIL_DRIVER=smtp

MAIL_HOST=ipadress

MAIL_PORT=587

MAIL_USERNAME="*******"

MAIL_PASSWORD="********"

MAIL_ENCRYPTION=''