How can I send email and SMS together using Laravel 5.5 ?
Should I use mailable and SMS service or Notification with SMS and How ?
You can create an event in laravel's App/Events folder.
put all the code for send mail and sms with there configuration, just call that event wherever you want to hit sms or mail.
You may create one function which will include both notify() method for an email and dispatch() method for message
example
public function Notification(Model $tender)
{
$user = access()->user();
/* Send confirmation email */
$tender->notify(new Email($user));
/* Send confirmation message */
Send::dispatch($user);
}
Then you will just call a single function that is Notification() which will do both sending email and message
Related
When the user registers, an email will be sent to confirmation
But how do I send a notification when a user updates their email?
Like when he registers
if you want to reverify your user's email , you should set his email_verified_at to null then call sendEmailVerificationNotification method .
in your user model (located in app\user) add this method :
public function sendNewVerification() {
$this->email_verified_at =null;
$this->sendEmailVerificationNotification();
}
and call it in your controller .
hope that would work.
[when send emails shows these error][1]ReflectionException Method App\Mail\Newsletter::__invoke() does not exist
these is my controlledispatch(new Newsletter($emailSubject,$emailBody,$arrayEmails));
these is my email classpublic function build() { return $this->view('emails.newsletter')->subject($this->emailSubject)->with(['msg'=> $this->emailBody]); }
these is my jobs public function handle() { $email = new Newsletter($this->emailSubject,$this->emailBody,$this->arrayEmails); Mail::to($this->arrayEmails)->send($email); }
As I understand, you create a job that in turn create and send the email object.
However, in the controller, you are not dispatching the job, you are dispatch the email object. And the email object doesn't contain either a handle or __invoke method so you see the error message.
The solution is to dispatch the job instead of the email.
This design is indeed unnecessary. Pls have a look at Mailables, create a queued mailable, and just send it.
I am new here.
I have a project in Laravel. I have one textarea and data from it is save in datavase. It works good. Now I would like to send automatical email to one specific email address with this data. It must be sent only one time with save to database.
I have no problem with sending email to customer with data but now I need to send email with data from this textarea to one specific email. It is a textarea what we have to buy for customer. It must be sent to our cooperation company.
Is it possible?
Ofcourse this is possible!
You should take a look at the following resources :
Observers
https://laravel.com/docs/6.0/eloquent#observers
Notifications
https://laravel.com/docs/6.0/notifications
-> specifically : https://laravel.com/docs/6.0/notifications#mail-notifications
yes, you can just trigger your function after saving: for example, after saving in controller.
public function store(Request $request){
$var = new Property; //your model
$var->title=$request->title; // the input that being save to database.
$var ->save();
// Send email to that input
Mail::send('email',['email'=>$request->title],function ($mail) use($request){
$mail->from('info#sth.com');
$mail->to($request->title);
});
return redirect()->back()->with('message','Email Successfully Sent!');
}
How to trigger a event for the Mail service?
Example
If mail template code equals mail.order.complete add bcc?
OctoberCMS is built on Laravel 5.1 and to do handle mail events you will need handle it within your Plugin.php file.
For example to handle the process just before the mails being sent:
class Plugin extends PluginBase
{
[...]
public function boot()
{
Event::listen('mailer.sending', function(){
});
}
}
To learn more about events in OctoberCMS and Laravel you can check out these links:
https://octobercms.com/docs/services/events
https://laravel.com/docs/5.1/events
https://laravel.com/docs/5.1/mail
I've an application that sends a mail to list of emails after submit the form. For this I'm using queue jobs to send mail to that list in the background. I'm using SMTP for this with mailtrap. I'm new to this queue jobs functionality.
this is my controller code to dispatch queue:
public function sendMail(Request $request)
{
$lists = List::where('list_id',$request->list_id)->pluck('email')->toArray();
$jobs = (new SendEmailToList($lists));
$this->dispatch($jobs);
return 'success';
}
And this is my job functionality in queue :
public function handle()
{
$lists = $this->lists;
Mail::send('email.test', array('email' => 'Sample'), function ($message) use ($lists) {
$message->to($lists);
});
}
I've a program file in the supervisor of my Linux system to queue:listen.
I've done all things but still it's not sending mail to all the list of emails. I've referred many of documentations but still same issue, all the documents given that to implement a QueueManager.
You should probably call Mail::queue or Mail::later instead of Mail::send.
Please refer to Mail documentation in case you've been missing something else.