doubinduo3364 2018-08-12 05:09
浏览 89

Laragon和Laravel - sendmail无法正常工作

I use Windows 10, Laragon and Laravel Framework.

And I setup the default Auth by calling php artisan make:auth

The problem is when I try to use the Forgot Password component, the 'sendmail' does not work. After I click Send Password Reset Link, nothing happened. And the Password Reset Link does not sent to the Laragon's Mail Catcher.

This is the configuration inside .env

MAIL_DRIVER=sendmail
MAIL_SENDMAIL="C:\laragon\bin\sendmail\sendmail.exe -bs"

And this is inside config/mail.php

'sendmail' => env('MAIL_SENDMAIL', '/usr/sbin/sendmail -bs'),
  • 写回答

1条回答 默认 最新

  • dthl8036 2018-08-12 07:21
    关注

    Firstly, I was using custom username and password I got from my Cpanel hosting email account to setup laravel mail. It did not go through via the sendmail config or smtp config.

    Reading up the doc i noticed laravel does extend the swift mailer class. I made my twick thus.

    $user = User::find(1);
          $text = (new WelcomeEmail($user))->render();
    
            // Create the Transport
            $transport = (new \Swift_SmtpTransport(env('MAIL_HOST'), 25))
              ->setUsername(env('MAIL_USERNAME'))
              ->setPassword(env('MAIL_PASSWORD'))
            ;
    
            // Create the Mailer using your created Transport RFCValidation
            $mailer = new \Swift_Mailer($transport);
    
            // Create a message
            $message = (new \Swift_Message('Happy to Have You Onboard'))
              ->setFrom([env('MAIL_FROM_ADDRESS') => env('MAIL_FROM_NAME')])
              ->setTo(['miracle@yahoo.com'])
              ->setBody($text , 'text/html')
              ;
              $message->setReadReceiptTo(env('MAIL_FROM_ADDRESS'));
    
    
    
            // Send the message
            $result = $mailer->send($message);
    

    Now the

    "new WelcomeEmail"

    is a Laravel mailable that bundles the view for the mail. You can brilliantly create your own mail class out of this above code to make your code tiny and extendable.

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题