-
-
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 Email helper class is a class that gets added to your components helper area And therefore available on every page And with which you can then send emails We could look at the helper Class by going to a component that has Included And then into helpers and The filename is usually the component name Email Opened it already here As you can see it's in just the basic abstract class That Thanks Jim Ellis emailer Which is this Gmail And it gets an instance of it And add to mail and then loads in Did the variables that's required Now We'll come back to this in a moment If you look at a component What you need to do first If you are gonna use this feature in any of your components That is open this Learning manager And then go to libraries and helpers And you'll see that there add email helpers been set to on Places the helper class in your component that's all it does It doesn't implemented anywhere else So At the moment that means that if you click yes here You need to still create fields That you are gonna load to your comp Fake area Now if you don't know about the config yet means you've skipped some tutorials But it's basically this area here Which gives you the option to the ability to add Configuration options to your components option area So if we click here I scroll down you'll see that there is Mail configuration and a whole lot of fields there Now these Fields correspond to the gym last default Fields if you didn't know So 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 fire file For our purposes I'm simply gonna show you how the fields look like We also have the dkm Yeah implementation available And 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 named and that is the The value that will be used in the code Ok I'll show you what I mean I just close out here Go back to the code So for example that work mailer Actually means That the name of the field is called Maile The name of the field is called that and that So goes on So these are all the fears that needs to be said If if if your component If we go back to the component Close this Utilities options area so I'm gonna open that Wanted to open your see there is a mail configuration and a dkm area Dkim So let's open a mail You see that it has the mailer status So it's over set to off then no emails will go out Auto on If it said 2 on you can decide whether you want to override the global function Adiglobal Variables Other global variables are set in your Gmail as components Global area 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 These are the main or the the global settings that will be used in the in any component that does Does not add These settings in their config So if you didn't create Those Fields and added it to your component but you text the the button to sort of add the helper Cars 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 override if you want your Component in two in 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 error can do So you use Global it falls back to the Joomla Global Otherwise you can override it on this level And send it out In a way that is What you would like Idk IM area Is there more advanced area which basically allows you to override Sorry not override to encrypt And secure email sent out from you do a centre Cape 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 Sam 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 stop periods here If this is said to know obviously it will not be used if it said to yes please ensure to add the values Otherwise it still will not be used Ok So that's basically the values that you need 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 take 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 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 at it and so you need to do that manually if you want it To be there if you don't like I've said before Before back to the gym allow Global So explain that you on the code level Basically it gets from the configuration The major function And then it checks whether it's global If it is global Then It Implements to Millers Values If it's not Global it implements your components values And That is basically what it will do Now you can read through the code But the most important area really is this area You 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 You know Your servers own limitations Since we obviously don't want you to spam people We do not Override those values when we are simply using the Joomla default Helper to Malawi an emailer 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 Are you can read up on on obviously the J in mailer Class from Joomla Read through this code here and see how we implemented These are the dkm 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 There Anyway that it's implementing these features It obviously is adding it to the mailer and most of the work is done in the major So it's basically adding the data to the mailer and the mail and 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 No work out well Then it shakes weather Your Component Helper class So your component has a helper class it's just this phone here Even has a storm message Variable A method So if we were to go check this You see that there is this storm message 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 Yeah Is the same signature you'll see it So basically this area that And that is dynamically updated to your component Seduces your component name here and your component name there But this store message Is basically No 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 That it's email So you can have different types so if you look at the the method The type can be anything We are obviously wanting to do different things on different types 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 did you can Maybe let you use her go If they login They can see messages sent to them in this kind of stuff So this is what the store message does and as you see it's a huge cross them Method that I Road And it does different things for different You can update it in change it cause the video copy it down don't really matter This is you realise this is actually something you ride 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 email In your component Maybe I should show you where I implemented at least In one area Ok so I have this component called job tracking system open it up You'll see that it actually has that function Adding the helper email it's got it selected you see there at help 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 When when it's created So let me show you how I can fermented it there So here is the job order And I would basically then Click on This area email now I can update that Do whatever email I like Testing At 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 email does it use this button it sends this Document 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 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 this send email function Get a set of values And then it basically gives it over to the scent Email server function which sends it as a JC object Sorry I Jason request to the server The scent Email is the Task And when I get 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 me explain how to use the Ajax class I'm great just touched on it briefly 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 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 2 years to ties Check for those values and then passes it over to the 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 this again Is a custom Script So if I was to go back here Close this You see there's the Indus Ajax method is a lot I mean look at that you can see it. Scroll down way down is a lot of other customers But this is another cross the method I've written Call send mail get the mail the HTML to type It it doesn't necessary Cleansing and whatever And then Eat Basically Aware Yeah We're calling the email helper We using the send method Passing the valuables and we Set the result in here And if the results is obviously true We will let the user know otherwise we give him the error You're 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 typed it 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 The necessary places as well as the body In the necessary place Right there So that it gets sent 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 Victor Jacks And then sends it off 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 So I think we are followed All the necessary standard requirements to make it useful to everyone 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