0

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?

Martin
  • 11
  • 4
  • Yes, you can use eloquent events to send email when a new record is created on specific model. see: https://laravel.com/docs/5.8/eloquent#events – Zohaib Sep 13 '19 at 09:36

2 Answers2

0

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

  • Could you be a bit more specific? – Stefano Groenland Sep 13 '19 at 10:30
  • I have this route for email: ` Route::get('/print/{id}', 'PrintController@printOrder')->name('print'); Route::get('/print-archive/{id}', 'PrintController@printArchive')->name('print.archive'); Route::get('/email/create/{id}', 'EmailController@create')->name('email.create'); Route::post('/email/send/{id} ', 'EmailController@sendOrderMail')->name('email.send'); Route::get('/email/{id}', 'EmailController@send')->name('email'); Route::get('/email-check', 'EmailController@checkEmails')->name('email-check');` – Martin Sep 13 '19 at 10:58
  • Could I add route in public funktion? – Martin Sep 13 '19 at 10:59
  • You could add a route somewhere to trigger the mailing if that is what u mean? I think you should take a look at the docs provided in my answer, and take a look at Laracasts to find some tutorials on how to use it. – Stefano Groenland Sep 13 '19 at 15:08
0

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!');
    }
Sajad Haibat
  • 697
  • 5
  • 12