-
-
Notifications
You must be signed in to change notification settings - Fork 178
025 How to use email helper in your components
Hi, I want to show you how to use the emailing helper class in your component. The email helper class is a class that gets added to your components helper area. And therefore available on every page. Which you can then send emails. We could look at the helper class by going to a component that has it 00:00:25 included. Then into helpers. The filename is usually the component name: Email. I've opened it already. As you can see it's in the basic abstract class. That takes Joomla's emailer, which is this Jmail. It gets an instance of it, 00:00:48 and adds it to mail and then loads in the variables that's required. We'll come back to this in a moment.
If you look at a component, what you need to do first, if you are going to use this feature in any of your components. Let us open Learning manager. Then go to libraries and helpers. 00:01:22 You'll see that the add email helpers been set to on. It places the helper class in your component, that's all it does. It doesn't implemented anywhere else. At the moment that means that if you click yes here, you need to still create fields, that you are going to load your config area.
Now if you don't know about the config yet, it means you've skipped some tutorials, but it's basically this(config) area here. 00:01:55 Which gives you the ability to add configuration options to your components option area. So if we click here(config - add) I scroll down you'll see that there is mail configuration and a whole lot of fields there. Now these fields correspond to the Joomla's default fields, if you didn't know. If you would like to create these fields and you need some info on what there should be in, what should be their names and everything. Then go look at the Joomla global configuration XML. And you'll see all the settings in that file. For our purposes I'm simply going to show you how the fields look like. 00:02:39 We also have the DKIM implementation available.
Even those fields you will need to look at the code to know what their names should be. So there's a difference of course between name and label and description. When we refer to name that is the value that will be used in the code. I'll show you what I mean. Go back to the code. For example that word mailer 00:03:13 means that the name of the field is called mailer. The name of the field is called that and that and so it goes on. So these are all the fields that needs to be set.
In your component there is a options area, I'm going to open that. Once it's open your see there is a mail configuration and a DKIM area. 00:03:45 Let's open the mail. You will see that it has the mailer status. So it's either set to off, then no emails will go out, or to on.
??? If it set to on you can decide whether you want to override the global function, the global variables. now the global variables are set in your Joomlas components Global area 00:04:10 So you would go to Global configurations And then You'd go to System No sorry It's server And then there's this mail settings here Ok Now these are the main or the the global settings that will be used in the in any component that Does not add 00:04:40 These settings in their config So if you didn't create Those Fields and added it to your component but you ticked the the button to sort of add the helper Class to your component Then That means that it will basically fall back to these settings in your Joomla default Area So Just that you know And these are the values that you need to overwrite if you want your 00:05:08 Component into some way to use other PHP mail or other send mail or Other What's the other one SMTP Values than that of the global you need to set it here And That is basically what this area can do So you use Global it falls back to the Joomla Global Otherwise you can overwrite it on this level And send it out In a way that is 00:05:38 What you would like The DKIM area Is there more advanced area which basically allows you to overwrite Overwrite sorry not overwrite to encrypt And secure email sent out from you to authenticate that it was really you that send it This is very helpful to sort of show your the people that receive these emails that it's not Spam and it's really comes from you it's more advanced I would encourage you to read up on it these are the values Usually would be required to be added private key a public key And obviously these type of areas here If this is set to no obviously it will not be used if it set to yes please ensure to add the values 00:06:25 Otherwise it still will not be used Ok So that's basically the values that you needs to still create Component does not do this for you You need to do it I could possibly foresee that In the future we might add this If you tick the helper class it adds these values for you But even then if you have done it manually We'll make sure that it doesn't add in twice 00:06:51 So as long as These values obviously be the same Names we will know actually a Somehow identify that And then not Add them dynamically So to avoid clashes But for the meantime it's not automatically being added and so you need to do that manually if you want it To be there if you don't like I've said before It will fall back to the Joomla Global 00:07:15 So to explain that you on the code level Basically it gets from the configuration The mailer function And then it checks whether it's global If it is global Then It Implements Joomlas Values If it's not Global it implements your components values 00:07:38 And That is basically what it will do Now you can read through the code But the most important area really is this area To know what is all the various Options that you have in the signature To send out Mail So it's able to really send out a lot of mail but Nonetheless You're also need to consider 00:08:04 You know Your servers own limitations Since we obviously don't want you to spam people We do not Overwrite those values. We are simply using the Joomla default Helper Joomla sorry jmailer And it is been extended from another class And so there are a lot of features and here And if you wanna know more about them you can read up on on obviously the jmailer 00:08:35 Class from Joomla As well as read through this code here and see how we implemented These are the dkim values that you would need And in your In your component To be able to use the dkim encryption But you could also read up on this and check out this function here up till there In its way that it's implementing these features It obviously is adding it to the mailer and most of the work is done in the mailer 00:09:05 So it's basically adding the data to the mailer and the mailer takes care of the rest Ok and so here it sends it off And if there is an error So let's say for some reason it didn't you know work out well Then it shakes whether Your Component Helper class So your component has a helper class it's just this file here 00:09:31 Even has a storemessage Variable or method So if we were to go check this You see that there is the storemessage method In the helper class this is a custom method that I wrote now you can write it anywhere you like But this signature should be the same Ok so here Is the same signature you'll see it 00:10:00 So basically this area that And that is dynamically updated to your component So it uses your component name here and your component name there But this store message Is basically Not You cannot change that but it takes to send email the recipient the subject the body to text only in the mode and it's says That it's email So you can have different types so if you look at the the method The type can be anything 00:10:30 We are obviously wanting to do different things on different type so if we send an SMS and we didn't Fail You wanna store the message if we did this or that So this this kind of feature Is it only used when something didn't work But also if it worked If it was sent It's gonna store it So it's a way to store the message So that you can 00:10:57 Maybe let your user go If they login They can see messages sent to them and this kind of stuff So this is what the store message does and as you see it's whole huge custom Method that I wrote And it does different things for different You can update it in change it pause the video copy it down don't really matter Just if you realize this is actually something you write up yourself you just need to make sure that that part is the same The rest is up to you Now you deal with it ok so that is really implementing the learning manager emailer 00:11:35 In your component Maybe I should show you where I implemented at least In one area ok let me do that Ok so I have this component called job tracking system if I open it up You'll see that it actually has that function Adding the helper email it's got it selected you see there add helper Set it to on Then the view in which we are using the email method is the job or the view Basically we want to email the client I did job order 00:12:21 When when it's created So let me show you how I implemented it there So here is the job order And I would basically then Click on This area here email now I can update that to whatever email I like Testing @ 00:12:45 vdm.io or something Just send it in to Nothing And Then once the email has been sent It actually let's me know See there in the it says email was sent successfully So That's basically what the emailer does it just this button it sends this Document 00:13:11 To my Client And also if I want to send it to my store The people that does the job I could also do that here I'm not gonna 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 I'm simply explaining to you how to use the email helper class So we will go to the code and I'll show you how I do it and 00:13:45 Mostly Maybe 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 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 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 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 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 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 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 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 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 Ok thanks for watching Until next time
- Home
- Beta Testing
- Custom Code
- PHP Settings
- Demo Component
-
Tutorials
- Hello World JCB
- Intro JCB Guide
- JCB Installation Steps
- Planning Components
- Field Type Overview
- Basic Fields Creation
- Admin View Management
- Advanced Field Usage
- Admin Component Integration
- Component Setting Customization
- Scripting Components
- Component FTP Options
- Dynamic Get Method
- Site View DynamicGet
- Site View Templates
- Template Setup Guide
- Layout Configuration Steps
- Custom Admin Management
- Adding Site Views
- Custom Admin Integration
- MySQL Demo Tweaking
- Global JCB Settings
- Custom Time Field
- User Helper Integration
- Email Helper Usage
- Message Store Email
- List View Unescape
- Export Import Customization
- Overwrite Custom Fields
- List Field Filtering
- Automatic Code Import
- Manual Code Implementation
- Component Export Import
- Custom Admin Buttons
- Translation Management
- Site View Permissions
- Component SQL Updates
- Site Edit Configuration
- JCB Backup System
- Helper Structure Integration
- JCB v2.5 Upgrade
- Tab Setup Guide
- JCB v2.6 Release
- Extended HelloWorld
- Field Rule Validation
- Community Snippets Intro
- Snippet Forking Tutorial
- Pull Request Snippets
- Library Manager Area
- Excel-based Translation
- Dynamic Router Details
- Database Auto Updates
- Subform Quick Demo
- VDM Package Import
- Dynamic File Inclusion
- File Field Upload
- Drag-n-Drop Upload
- Quick HelloWorld JCB
- Non-database Fields
- Dashboard Customization
- Menu Prefix Toggle
- Community JCB Packages
- Collaborative JCB Workflow
- JCB Package Install
- JCB JAB18 Event
- Convenient New Fields
- Component Language Strings
- Library Functionality Anticipation
- Join Field Relations
- License Template Change
- Code Reusability
- Local Dev Environment
- Extended Field Types
- Joomla Custom Fields
- Custom Field Expansion
- Site View Listing
- Run Expansion Method
- Form Site View
- Field URL Update
- Additional Helper Methods
- Field Validation Rules
- New Placeholder Feature
- Component Config Params
- Per-field Default Values