为什么我的电子邮件不会在laravel

时间:2018-04-06 11:34:23

标签: php laravel email

我正在研究一个大学项目,我想使用MAIL_DRIVER =邮件发送电子邮件我昨天有这个工作,现在它似乎停止了工作?我在下面附上了我的代码。

Contact.blade.php

    <!DOCTYPE html>

<html lang="en">

    <head>

        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">

        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

        <style>

            .invalid-feedback {

                display: block;
            }

        </style>
        <title> Contact </title>

    </head>

    <body>

        <div class="container">

            <h1> Feedback Form </h1>

            <div class="row">       
                <div class="col-md-6">

                    @if (Session::has('flash_message'))

                        <div class="alert alert-success">{{ Session::get('flash_message') }}</div>

                    @endif

                    <form method="post" action="{{route('contact.store')}}">

                        {{ csrf_field() }}

                        <div class="form-group">
                            <label> Full Name: </label>
                            <input type="text" class="form-control" name="name">
                            @if ($errors->has('name'))
                            <small class="form-text invalid-feedback"> {{ $errors->first('name') }}</small>
                            @endif
                        </div>

                        <div class="form-group">
                            <label>  Email: </label>
                            <input type="text" class="form-control" name="email">
                            @if ($errors->has('email'))
                            <small class="form-text invalid-feedback"> {{ $errors->first('email') }}</small>
                            @endif
                        </div>

                        <div class="form-group">
                            <label> Technical Ability: </label>
                            <textarea name="message" class="form-control"></textarea>   
                            @if ($errors->has('message'))
                            <small class="form-text invalid-feedback"> {{ $errors->first('message') }}</small>
                            @endif      
                        </div>


                        <button class="btn btn-primary">Submit</button>


        </form>
        </div>

        </div>
        </div>      

    </body>

</html>

ContactMessageController

        <?php

    namespace App\Http\Controllers;

    use Mail;


    use Illuminate\Http\Request;



    class ContactMessageController extends Controller
    {

        public function create(){

            return view('contact');
        }

        public function store(Request $request)

        {

    $this->validate($request,[    

        'name' => 'required',
        'email' => 'required|email',
        'message' => 'required'

        ]);

        Mail::send('emails.contact-message', [

            'msg' => $request->message

        ], function ($mail) use($request) {

            $mail->from($request->email, $request->name);

            $mail->to('niamh3516@hotmail.co.uk')->subject('Contact message');

        });

        return redirect()->back()->with('flash_message', 'Thank you for your message');

        }
    }

我的.env看起来像这样:

MAIL_DRIVER=mail
MAIL_HOST=smtp.live.com
MAIL_PORT=25
MAIL_USERNAME=myemail@hotmail.co.uk
MAIL_PASSWORD=password

我收到一条消息,说“谢谢您的留言”,它似乎有效,但我没有收到电子邮件。

提前致谢。

0 个答案:

没有答案