Updated 025 How to use email helper in your components (markdown)

Amigo 2019-06-13 17:33:10 +02:00
parent a921b5210f
commit 84a4b16906
1 changed files with 8 additions and 3 deletions

@ -26,7 +26,7 @@ If it set to on you can decide whether you want to override the global function,
### Joomla Global Configuration - Server
So you would go to global configurations, and then you'd go to server, and then there's mail settings. Now these are the main or the the global settings that will be used in any component that does not add [00:04:40](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m40s) these settings in their config. So if you didn't create those fields and added it to your component, but you ticked the button to add the helper class to your component, that means that it will fall back to these settings in your Joomla default area. And these(Main Settings) are the values that you need to override.
So you would go to global configurations, and then you'd go to server, and then there's mail settings. Now these are the main or the the global settings that will be used in any component that does not add [00:04:40](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m40s) these settings in their config. So if you didn't create those fields and added it to your componyou can see you passing the HTML on the subject to it. ent, but you ticked the button to add the helper class to your component, that means that it will fall back to these settings in your Joomla default area. And these(Main Settings) are the values that you need to override.
### Component Builder Email Switch Options
@ -53,5 +53,10 @@ And if there is an error, let's say for some reason it didn't work out well. The
Maybe I should show you where I implemented at least in one area. I have this component called job tracking system. I open it up, you'll see that it actually has that function: Add email helper. Set it to on. The view in which we are using the email method is the job order view. Basically we want to email the client, it did a job order [00:12:21](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m21s) when it's created. So let me show you how I implemented it there. So here is the job order. I would basically then click on email. I can update it to whatever email I like, [00:12:45](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m45s) testing@vdm.io or something. Just send it in to nothing. Then once the email has been sent, it let's me know. In the top right it says email was sent successfully. That's basically what the emailer does. It just this button that sends the document [00:13:11](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m11s) to my client. If I want to send it to my store, the people that does the job, I could also do that here. I'm not going to explain to you the reality of taking this content, adding it to the email and sending it. That I would suspect you need to know and you need to learn or study to do that yourself. I'm simply explaining to you how to use the email helper class.
### Above Example In Code
????
So we will go to the code and I'll show you how I do it and [00:13:45](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m45s) I'll give you some pointers. but I won't go into detail About how that is done Ok so let's go to the to the code So here we are in the job order So first thing here is obviously some JavaScript So there's the send email function and Gets a set of values And then it basically gives it over to the send Email server function which sends it as a J object [00:14:20](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m20s) Sorry a json request to the server The send Email is the Task And when it gets a response that's when you get the notification Ok so that's Simply the JavaScript of it So now if we go to PHP Previous Tutorials we explain how to use the Ajax class I'm gonna just touched on it briefly [00:14:47](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m47s) You basically have your input here This is where you put set up your controller Let me show you that So you'll see in your controller There is this send email Class that's what basically was defined And this field here And you see that there is Basically three variables And they are [00:15:12](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h15m12s) Should be filtered in this way and they are fast over to these methods And you should be logged in user So if you look at the code again it basically this is the task down here it triggers the task It checks for those values and then passes it over to This method which is in the Model is a model So we go to models Ajax So here is the the model let's just scroll down to the send email So here is the send email and this again [00:15:47](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h15m47s) Is a custom Script So if I was to go back here I Close this You'd see there's the in this Ajax method is a lot I mean look at that you can see that scroll down way down is a lot of other custom methods here But this is another custom method I've written Call send mail gets the mail the HTML to type It it does the necessary Cleansing and whatever [00:16:14](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h16m14s) And then It Basically Over Here We're calling the email helper We using the send method we Passing the valuables and we Set the result in here And if the results is obviously true [00:16:38](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h16m38s) We will let the user know otherwise we give him the error ok so that That is the The short end of it I'm also using this email body to help me build the the email because I want to Make sure that it's got all the necessary HTML and stuff so you can Pause this video and type that out if you like But this is the email body that I usually use and you can see you passing the HTML on the subject to it And it simply adds the the subject to the Email [00:17:15](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m15s) The necessary places as well as the body In the necessary place Right there So that it gets send in a way that's more appropriate And then That's all happening right here Ok and that is what I'm passing in here So a custom method which gets the data from the Ajax And then sends it off [00:17:43](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m43s) So that's a quick tutorial on how to implement sending emails through your component Using the email helper class Obviously the email helper class Is Available on GitHub in in the component Builder And if you feel that our implementation lacks some professional Help then please do make a commit to Quest or send me an email And we'll gladly update an improved this class Although I think we are followed All the necessary standard and requirements to make it useful to everyone [00:18:26](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m26s) Ok thanks for watching Until next time
So we will go to the code and I'll show you how I do it and [00:13:45](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m45s) I'll give you some pointers. I won't go into detail about how that is done. Let's go to the code. We are in the job order, first thing here is some JavaScript. There's the send email function and gets a set of values. And then it gives it over to the send email server function, which sends it as a [00:14:20](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m20s) json request to the server. The send email is the task and when it gets a response that's when you get the notification. That's simply the JavaScript of it.
If we go to php, in previous tutorials we explain how to use the Ajax class.
I'm going to touched on it briefly. [00:14:47](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m47s) You have your input here(ajax input). This is where you set up your controller. So you'll see in your controller there is send email class what was defined in this field here(see video). And you see that there is three variables, and they [00:15:12](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h15m12s) should be filtered in this way and they are pass over to these methods and you should be login user. So if you look at the code, again this is the task(sendEmail), down here it triggers the task. It checks for those values and then passes it over to this method(sendmail) which is in the model. We go to models, Ajax. Here is the the model(see video). Let's just scroll down to the sendemail. Here is the sendemail and this again [00:15:47](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h15m47s) is a custom script. So if I was to go back here, I close this, you'd see there's the ajax method, there is a lot, I mean look at that, you can see that scroll down way down is a lot of other custom methods. This is another custom method I've wrote, it's called sendemail, it gets the mail, the HTML, the type. It it does the necessary cleansing and whatever. [00:16:14](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h16m14s)
Over here(see video) we're calling the email helper. We using the send method, we passing the valuables, and set the result in here. If the results is true, [00:16:38](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h16m38s) we will let the user know, otherwise we give him the error. I'm also using this email body to help me build the email because I want to make sure that it got all the necessary HTML and stuff. You can pause the video and type that out if you like. This is the email body that I usually use. It simply adds the subject to the email, [00:17:15](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m15s) the necessary places as well as the body in the necessary place that it gets send in a way that's more appropriate. That all is happening right here. That is what I'm passing in here. A custom method which gets the data from the ajax and then sends it off. [00:17:43](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m43s) That's a quick tutorial on how to implement sending emails through your component, using the email helper class. The email helper class is available on GitHub in the component builder. If you feel that our implementation lacks some professional help then please do make a commit to quest or send me an email. We'll gladly update an improved this class, although I think we followed all the necessary standard and requirements to make it useful to everyone.