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

Amigo 2019-07-04 09:09:52 +02:00
parent b3519a0cc1
commit 5928b5a0ec

@ -55,16 +55,15 @@ If for instance an error occurres, then it verifies whether the component Helper
Here follows a example of how it is implemented at least in one area. For instance here is this component, Job Tracking System. It has that function: Add Email Helper. Set it to 'On'.The view(Admin View) in which the email method is used, is the 'Job Order' view. In this case the client needs to be emailed when a job order had been created. [00:12:21](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m21s) Here follows a example of how it is implemented at least in one area. For instance here is this component, Job Tracking System. It has that function: Add Email Helper. Set it to 'On'.The view(Admin View) in which the email method is used, is the 'Job Order' view. In this case the client needs to be emailed when a job order had been created. [00:12:21](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m21s)
This is how it is implemented.(See video) Here is the Job Order. When Email is selected it may be updated to any preferred email. like for example: 'testing@vdm.io'. [00:12:45](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m45s) Once the email has been sent, it will be confirmed in the top right. [00:13:11](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m11s)It is this button that sends the document to the client.<<<<<<<<<<<<<<<<<<<<<<<<<<<<<, This is how it is implemented.(See video) Here is the Job Order. When Email is selected it may be updated to any preferred email. like for example: 'testing@vdm.io'. [00:12:45](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m45s) Once the email has been sent, it will be confirmed in the top right. [00:13:11](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m11s)It is this button that sends the document to the client.
### Above Example In Code ### 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. 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. Go to the code.(Editting the Admin View) [00:13:45](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m45s)
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) In the 'Job Order' is a JavaScript area. The Send Email function may be seen which collects a set of values and transfers it to the 'sendEmail server' function, which sends it as a 'json' request to the server. [00:14:20](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m20s) The 'sendEmail' is the task and when it gets a response, it gives the notification.
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. In the 'Job Order' is a PHP area. How to use the Ajax class had been explained in previous tutorials but just a brief touch on it again. [00:14:47](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m47s) Here is the input(ajax input) where the controller has to be set up . In the controller there is 'sendEmail' class that was defined in this field (see video). [00:15:12](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h15m12s) There are three variables, and should be filtered and are transfered to these methods and you should be logged in 'User'. Looking at the code, again this is the task 'sendEmail', it triggers the task and checks for those values, then transfers it to this method 'sendMail' which is in the model. Go to Models and to Ajax. Scroll down to the 'sendEmail'. [00:15:47](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h15m47s) This is a Custom Script. In closing this, the Ajax method can be seen. This is another Custom method which had been written by VDM, it's called sendEmail, it gets the 'mail', the 'HTML' and the 'type'. It it does the necessary cleansing etc. [00:16:14](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h16m14s) The Email Helper is requested. Then the 'Send' method is used and the variables are transfered. Then set the 'result'. If the result is 'true', [00:16:38](https://www.youtube.com/watch?v=tp6mMUTOF2Y&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h16m38s) the user is notified, otherwise he receives 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.