Reputation: 41
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'); });
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('[email protected]','Seal Travels');
$message->to('[email protected]', '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');
}
}
}
Upvotes: 2
Views: 980
Reputation: 41
I used double quotes and called the username from the textbox using $username = ($_POST['username']);
Mail::send([], [], function($message){
$username = ($_POST['username']);
$message->from("[email protected]","Seal Travels");
$message->to("[email protected]", "Yvonne");
$message->subject("Login Credentials");
$message->setBody("Your Username is <b>$username</b> ", "text/html");
});
Upvotes: 1