0

I am using windows machine and trying to send Emails upon user registration in Laravel. Following is my code. Am new to laravel and i don't know how to use it.

First i run flowing command

php artisan make:mail WelcomeMail

Following is the code in Registration controller

public function storeUsers(Request $request)
    {
        $postdata = $request->all();
        $user = new User;
        $hashedRandomPassword = Hash::make('password', [
            'rounds' => 12
        ]);
       $user = new User;
       $user->name=$postdata['user_name'];
       $user->email=$postdata['email'];
       $user->password= $hashedRandomPassword;
        $user->save();
       Mail::to($postdata['email'])->send(new WelcomeMail($user));
       // return $user;

        if( count(Mail::failures()) > 0 ) {

            echo "There was one or more failures. They were: <br />";

            foreach(Mail::failures() as $email_address) {
                echo " - $email_address <br />";
            }

        } else {
            echo "No errors, all sent successfully!";
        }

       exit();


       return redirect('users');
    }

I have also configured smtp settings in both ENV file and config->mail.php file in laravel.

What is the issue?When i tired to send emails its always generating There was one or more failures error section i echoed in code

  • in your config fiile, have you configured an SMTP server? If you don't have access to one you can mail with you can set up something locally like https://www.hmailserver.com/ you can configure – Tschallacka Feb 07 '20 at 09:53
  • Add your code inside try and catch and check what error you are getting. try{ // add your sending email code here } catch(\Exception $e){ print_r($e->message()) } – Sehdev Feb 07 '20 at 09:55

0 Answers0