I have a function to send a email for registered users. This is how i am checking if an email should be sent or not.
$email=$details->email;
$subject = 'Looking for blood donor';
$status=Mail::send('emails.welcome', $data, function($message)
use($subject,$email){
$message->from('no-reply#bloodlink.com', 'Blood Link');
$message->bcc('no-reply#bloodlink.com');
$message->to($email)->subject($subject);
});
I am using if for check email sent or not but it not work..
if($status)
{
return Response::json(array('status'=>'success',
'data'=>("Your email has been sent successfully")
), 200);
}else{
return Response::json(array('status'=>'error',
'data'=>("something went wrong..!!")
), 200);
}
The Mail::send() method doesn't return anything.
You can use the Mail::failures() (introduced in 4.1 I think) method to get an array of failed recipients, in your code it would look something like this.
Mail::send('emails.users.reset', compact('user', 'code'), function($m) use ($user)
{
$m->to($user->email)->subject('Activate Your Account');
});
if(count(Mail::failures()) > 0){
$errors = 'Failed to send password reset email, please try again.';
}
Have a look into failure method, here
Related
I have a function to send email to customer for every new registration. and my client want to record any unsuccessfull email sent (i.e if email address is wrong).
i try using try-cacth and mail::failure.
try{
Mail::send('mail.mail', compact(''), function ($message) use ($) {
$message->from();
$message->subject();
$message->to();
});
}
catch(\Swift_TransportException $e){
}
mail:failures
if (Mail::failures()) {
echo ('error');
}
but this working if network failure, such as email host is down. how to record/get info if email wasnt delivered because email address/domain not found.
i get this info in email if email wasnt delivered. but how to record it the ddetails into database.
Address not found
Your message wasn't delivered to asna#asmas.cl because the domain asmas.cl couldn't be found. Check for typos or unnecessary spaces and try again.
look my below code gets a json resposnse after sending an sms, your system should also get a response json after sending the email. The json carrys a set of data. check the particular data response you wish for and update it accordingly on your table.
$responseJson = json_decode($response, true);
// data returned --> [{"status":"200","response":"success","message_id":82682342,"recipient":"4113122"}]
$status = ($responseJson[0])['status'];
$responseDescripition = ($responseJson[0])['response'];
Log::info('API status >>>>> ' . $status);
Log::info('API Response Description >>>>> ' . $responseDescripition);
if (($responseJson[0])) {
DB::table('mess')->where('id', $request->input('template'))
->update([
'sentstatus' => '1',
'status' => $status,
'responsecode' => $responseDescripition,
'sent_on' => \Carbon\Carbon::now(),
]);
}
I am trying to determine how to send an email to a group of recipients (as an array) through Laravel's Mail facade, but I would like the emails sent as individual emails as opposed to one bulk email in which all recipients' emails will be viewable.
I have an array of email addresses, $attendees, to whom the email is sent once validation passes. One way I could resolve this is to send to $attendees as 'bcc' vs. 'to,' but ideally I would like the email to be sent 'to' each recipient.
First and foremost, this following block of code DOES work, and is successful at emailing the array of $attendees -- but again, they all receive the email together and are able to view the collection of email addresses/emails of other recipients in the 'to' field when they receive the email, which I do not want to be the case.
if ($validator->fails()) {
$messages = $validator->messages();
return Redirect::to(URL::previous())
->withErrors($validator)
->with('subject', $mailDetails['subject'])
->with('body', $body)
->with('eventId', $eventId);
} else {
Mail::send('emails.event_attendees', $mailBody, function($m) use ($mailDetails) {
$m->from('noreply#helpinghabit.com', $mailDetails['orgName']);
$m->to($mailDetails['attendees']);
$m->bcc($mailDetails['sender']);
$m->subject($mailDetails['subject']);
});
return redirect()->back()->with('message', "Your email has been sent!");
};
I tried to accomplish this using a foreach loop like so:
if ($validator->fails()) {
$messages = $validator->messages();
return Redirect::to(URL::previous())
->withErrors($validator)
->with('subject', $mailDetails['subject'])
->with('body', $body)
->with('eventId', $eventId);
} else {
foreach ($attendees as $k) {
Mail::send('emails.event_attendees', $mailBody, function($m) use ($mailDetails) {
$m->from('noreply#helpinghabit.com', $mailDetails['orgName']);
$m->to($attendees[$k]);
$m->bcc($mailDetails['sender']);
$m->subject($mailDetails['subject']);
});
};
return redirect()->back()->with('message', "Your email has been sent!");
};
... but this returns an empty response error and tells me that no data was sent.
Any ideas? Thanks in advance for your help!
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 .
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;
am having some sort of an issue with sending mails from my website with Laravel 4, I followed the on-line documentation but haven't successfully sent a mail with Laravel my code is as show below.
Mail::send('emails.contactmail', $data, function($message)
{
$name = Input::get('name');
$email = Input::get('email');
$message->from($email, $name);
$message->to('info#mysite.org', 'Info at My Site')
->subject('Website contact form');
});
I use following code for sending temporary password in case of forgot password
public function postForgotPassword(ForgotPasswordRequest $request){
$email=$request->email;
$objUser=DB::table('users')
->where('email','=',$email)
->select('email','id','first_name','last_name','user_group_id')
->first();
$string = str_random(15);
$pass=\Hash::make($string);
$objUser2=User::find($objUser->id);
$CURRENT_TIMESTAMP=new DateTime();
$objUser2->temporary_pass=$pass;
$objUser2->pass_status=1;
$objUser2->updated_at=$CURRENT_TIMESTAMP;
$objUser2->save();
$data=array("email"=>$email,"pass"=>$string,"first_name"=>$objUser->first_name,"last_name"=>$objUser->last_name);
$email=array("email"=>$email);
Mail::send('emails.forgot_password',$data, function($message) use($email) {
$message->to($email['email'],'MyProject')->subject('Password Recovery ');
});
return Redirect::to('auth/login')->with('flash_message','Check your email account for temporary password');
}
And I write email template in forgot_password.blade.php which is located in view.emails folder.