Laravel : Password reset email check against user - php

I have the following code to send the password reset email to the users email which is working:
$response = $this->passwords->sendResetLink($request->only('email'),function($message)
{
$message->subject('Password Reminder');
});
What i want is that user should write their username instead of email, And i will check the email against that username , And will send the email.So i came up with this idea.
$usernameToEmail = User::where('name','=', Input::get('username'))->first();
$response = $this->passwords->sendResetLink(['name' => $usernameToEmail],function($message)
{
$message->subject('Password Reminder');
});
Which is not working also.
Am i missing something ?

You're close, but your $usernameToEmail variable contains a User object, not an email string. Most likely you just need to add a method to your chain:
$usernameToEmail = User::where('name','=', Input::get('username'))->first()->email;

Related

how to encoding email address inside email content

I'm using laravel 8.
I want to sending reset password link. but when I want to append email address to token as parameter:
public function toMail($notifiable)
{
return (new MailMessage)
->subject('.....')
->action('Reset', url('password/reset', $this->token.urlencode('&email='.$notifiable->email)))
}
the result of email content is:
http://****/password/reset/326e15aad30c49acc55d39ff6983ccf33a838311b48c00318bc23e1a354b2c5b%2526email%253DS.M_Emian%2540yahoo.com
this output cannot decode from javascrpit.
You can send the Password Reset link using the existing functionality in Laravel 8 as documented here
use Illuminate\Support\Facades\Password;
$status = Password::sendResetLink(
$request->only('email')
);
More info about Password reset

Laravel Mail, "from" always need to be the same as "username"?

If I'm firing an e-mail from mysite#mysite.com.br but if I change the from to another e-mail like company#company.com.br it falls into Mail::failures()
It DOESN'T Works
// username = 'mysite#mysite.com.br'
// password = 'mypassword'
Mail::send("mail.test", [], function ($message) {
$message->to('client#client.com')
->from('company#company.com' , 'Company');
});
client#client.com falls into Mail::failures()
It Works
but if I change it to:
// username = 'mysite#mysite.com.br'
// password = 'mypassword'
Mail::send("mail.test", [], function ($message) {
$message->to('client#client.com')
->from('mysite#mysite.com.br' , 'My Site');
});
The problem was in my mail server, I talked with the support from my server and he said It its block for fraude reasons

Laravel how to pass the name of the user when I sent the forgot password function

I want to make my mail more detailed when the user has sent a forgot password reset link to his/her email. This is the sample of the picture when receiving a reset password link.
I want to add some details here that the Hello should be Hello! (user name here)
Here is the code that I added in my SendsPasswordResetEmails.php
public function sendResetLinkEmail(Request $request)
{
$this->validateEmail($request);
// We will send the password reset link to this user. Once we have attempted
// to send the link, we will examine the response then see the message we
// need to show to the user. Finally, we'll send out a proper response.
$response = $this->broker()->sendResetLink(
$request->only('email')
);
$applicant_name = Applicant::where('email', $request->email)->get()->value('name');
return $response == Password::RESET_LINK_SENT
? $this->sendResetLinkResponse($response)
: $this->sendResetLinkFailedResponse($request, $response);
}
and it should pass the data to app\Notifications\ApplicantResetPasswordNotification.php
public function toMail($notifiable)
{
return (new MailMessage)
->from('vcc3dummy#gmail.com', 'CCV3')
->greeting('Hello! Applicant Name') // Applicant name pass here
->line('You are receiving this email because we received a password request for your account.')
->action('Click here to Reset Password', route('applicant.reset', $this->token))
->line('If you did not reset your password, no further action is required.');
}
Looking for help on how to pass the data or how to query it.
Would appreciate if someone could help me
Thanks in advance.
In your ApplicationResetPasswordNotification.php you can use the $notifiable variable as follows:
public function toMail($notifiable)
{
return (new MailMessage)
->from('vcc3dummy#gmail.com', 'CCV3')
->greeting('Hello!' . $notifiable->name) // Applicant name
...
}
Please mark as answer if that works for you!
This is the another way to send the mail in laravel -
Put that data you want to use/show in email template.
$data = [
'email' => $email,
'remember_token' => $remember_token,
'name' => $applicant_name
];
Mail::send('emails/forgotmail', $data, function ($message) use ($data) {
$message->from('youremail#gmail.com');
$message->to( $data['email'] )->subject('Forgot Password Link');
});
Where as 'email/forgotmail' is in 'resources/views/email/forgotmail.blade.php' that you have to create. So that here you can put your email template over here and make use of $data in it .

FosUserBundle: password reset request link is sent instead of resetting link

I am trying to send email with password reset link. This is my method:
public function sendPasswordResettingEmail(User $user){
$url = $this->router->generate('fos_user_resetting_reset',
array('token' => $user->getConfirmationToken()), UrlGenerator::ABSOLUTE_URL);
$html = $this->templating->render('CoreBundle:Email:password_reset.email.twig', array(
'user' => $user,
'confirmationUrl' => $url
));
$message = \Swift_Message::newInstance()
->setContentType('text/html')
->setSubject('Password reset')
->setFrom(array(self::EMAIL_FROM => 'App'))
->setTo($user->getEmail())
->setBody($html);
$this->service->get('mailer')->send($message);
}
But I get email with
http://127.0.0.1:8000/resetting/request
link, which takes me to a form asking for email or username. I need to submit my email address again to get resetting
http://127.0.0.1:8000/resetting/reset
link.
Is it possible to get reset link and skip request step? because I am already providing user parameter to method.

Laravel mail cannot send from field

Im trying to send mail from laravel and when i add the dynamic from field i get this error:
"Expected response code 250 but got code "501", with message "501 A syntax error was encountered in command argument.."
this is the code:
$user = Input::get('user');
Mail::send('template.contact', $user , function($message) use ($user)
{
$email = $user['email'];
$message->from($email , 'name'); thats doesnt
//$message->from('us#example.com', 'Laravel'); that work
$message->to('test#gmail.com', 'contact us' )->subject($user['subject']);
});
and the user is coming from angular -
service:
this.sendConatctMail = function(data) {
return $http.post('send-contact-mail', {user: data});
}
and controller:
contactService.sendConatctMail($scope.user);
Here's one way you can solve this.
Let's assume the data on this.sendConatctMail = function(data) { is a object like this:
var data {
email: 'some#email.com',
// other field: values
}
Right before you post it, you should convert it into JSON string like this:
return $http.post('send-contact-mail', {user: JSON.stringify(data)});
Then on Laravel/PHP side, decode that back into an array and use it like this:
if (Input::has('user'))
{
// Decode json string
$user = #json_decode(Input::get('user'), true);
// Proceed if json decoding was success
if ($user)
{
// send email
Mail::send('template.contact', $user , function($message) use (&$user)
{
$message->from($user['email'], 'name')
->to('test#gmail.com', 'contact us')
->subject($user['subject']);
});
}
}
I don't know if this will help you, but whenever I send emails through Laravel, I need to alter the use(...) section a bit. You have:
$user = Input::get('user');
Mail::send('template.contact', $user , function($message) use ($user)
...
Try changing it to this and see what happens:
$user = Input::get('user');
Mail::send('template.contact', array('user' => $user), function($message) use (&$user) {
$message->from($user['email'], $user['name']);
$message->to('test#gmail.com', 'contact us')->subject($user['subject']);
}
2 changes I made:
array('user' => $user)
and
use(&$user)
I don't know if that will help you, but I have working emails on my application that look almost identical to yours, except for the &$variable instead of just $variable
Good luck!
The problem is with your $email = $user['email'];
try checking your $user['email']
if $message->from('us#example.com', 'Laravel'); this works
then
$email = $user['email'];
$message->from($email , 'name');
this must work...
I have tried the same without much trouble...
In my application I needed to pass the _token variable in all my ajax request any such problems??

Categories