简体   繁体   中英

Send username and password to user's email Laravel

I am trying to send the username and password to the user's email when the administrator adds them to the system. How should I set this $message->setBody('Your Username is <b>$username</b> <br> Your Password <b>$password</b>', 'text/html'); }); $message->setBody('Your Username is <b>$username</b> <br> Your Password <b>$password</b>', 'text/html'); }); to fetch the username from the textbox and the password which is autogenerated.

public function adduser(Request $request)
    {
        $email = $request->input('email');
        $username = $request->input('username');
        $password = Hash::make(str::random(5));
        $dateadded = $request->input('dateadded');

        if ($email != '' && $username != '' && $password != '' && $dateadded != '')
        {
            $data = array('email' => $email, "username" => $username, "password" => $password, "dateadded" => $dateadded);
            $value = AdministratorModel::adduser($data);

            if ($value)
            {
                echo "<script type='text/javascript'>alert('User Added');</script>";

                Mail::send([], [], function($message){
                    $message->from('sealtravels19@gmail.com','Seal Travels');
                    $message->to('yvonnekusiima00@gmail.com', 'Yvonne');
                    $message->subject('Login Credentials');
                    $message->setBody('Your Username is <b>$username</b> <br> Your Password <b>$password</b>', 'text/html');
                });
                echo "<script type='text/javascript'>alert('Login Credentials sent');</script>";

                return redirect()->action('AdministratorController@userrecords');
            }
            else
            {
                echo "<script type='text/javascript'>alert('User already exists');</script>";
                return view('Administrator/AddUserView');
            }
        }
    }

I used double quotes and called the username from the textbox using $username = ($_POST['username']);

                    Mail::send([], [], function($message){
                    $username = ($_POST['username']);
                    $message->from("sealtravels19@gmail.com","Seal Travels");
                    $message->to("yvonnekusiima00@gmail.com", "Yvonne");
                    $message->subject("Login Credentials");
                    $message->setBody("Your Username is <b>$username</b> ", "text/html");
                });
                

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM