发送用户名和密码到用户的电子邮件Laravel

时间:2020-07-31 20:05:57

标签: php laravel

当管理员将用户名和密码添加到系统时,我正在尝试将用户名和密码发送到用户的电子邮件中。 我应该如何设置此$message->setBody('Your Username is <b>$username</b> <br> Your Password <b>$password</b>', 'text/html'); });来从文本框中获取用户名和自动生成的密码。

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');
            }
        }
    }

1 个答案:

答案 0 :(得分:1)

我使用了双引号,并使用$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");
                });