 Welcome back to the channel. In today's video, I'm going to show you how you can get your data that you collect on a contact form seven, send it to an API or even use it to mail it elsewhere. So what we're going to do is we're going to use a function that's embedded in contact form seven and then we'll use some objects that are available in the plugin itself. So let's write our own custom plugin. So in my plugins, I'm going to create a new folder and I'll call it a contact form seven API sender. And then I'll copy this drag and drop it in my editor. I'll add a file with a PHP extension. Of course, I'll start with the PHP here and I'll use my start plugin snippet to make this possible. So I'm going contact form seven API sender, I'll change the URIs and then I'll leave everything else as it is. So I'm going to my plugin section and I'll activate the sender and then I'll begin coding what we have here. So inside here, we're going to start with an action hook that comes contact form seven. So I'll write a function here and call it take you press contact form seven API sender. And this is the function that I'm going to use with my hook. And the hook that we are looking for is actually called WPC for WordPress contact form seven mail sent. And that's what we are looking for. Now this hook gives us an object which we can use. And that's basically the contact form that we have. Now with this object, we're able to get the title from it. So we'll get the title. And what we're going to do is save this as a variable. We'll call it title is equal to the contact form title. Now why do we need to save the title is because we might have so many contact forms on our particular website. And we might just want to use this one. So we can see here the title is called web response. So I'll copy this come here. And I'm going to do an if statement and say if the title is equal to don't add a string web response. Then we are going to do a couple of things with this particular form. Now if we want to work with the submitted data, we're going to have to use the WordPress contact form seven underscore submission object, which is basically a class that is from contact form seven. Now with this particular class, it has a particular method inside it. If you do not understand the terminology I'm using it's because the plugin uses object oriented programming where you have a class and a class has inside it a function and a function in the upgrade in OOP object oriented programming is what we call a method. So this class has that static method which we call which is called get instance. So the first thing we do is we run this submission class and we're going to store it inside a variable. So we'll call this submission is equal to the submission class and we're going to get an instance of that. So next we are going to say if the submission is true, then we shall have something running. So submission, if the submission is true, what we're going to do is we're going to get the posted data and we're going to say the posted data is equal to the submission, which is a reference to us getting an instance of the submission class. And we're going to get a method from there, which is get posted data. So we're going to get the posted data and we're going to save it inside this variable. So after getting our posted data set up, we are now going to start getting the different fields that are inside our form. I'll go back to my page right here, copy the code that is here. And I'm going to come and just paste it here and comment it out. The reason I copy it is because I want to get these particular IDs of our fields. So I'll copy this and say if I want to get the name variable name, it's going to equal to the posted data. And then of course, the posted data is going to come as an array of data. So if I want to pick off the name, I'll have to use this ID of your name. Now, depending on how your IDs look like, you might need to change this or you might need to get the ones that are available for you. So what I'm going to do is just duplicate this over and then get all the other pieces. So I'm going to get the email, I'll get the subject and then change it to your subject here. Now get the message, which I also call the message right here. I'll take away those comments. And that means we have all this content that we actually wanted to have here. Now, what I'm going to do is I'm going to that dump all this information. And then I'm going to choose die or WP die so that I can see what happens. So let me get the name, dump it, let me get the email, then the message. So copy this and pass this serve. Now let's go to the front end and try to send a message. So I'm going to copy this code. So I'll put a short code and I'll call this contact form seven. And then I'll publish this page. And I'll go to view the page. Now when we reach here, I'm going to add in my names. So take a press, I'll add in my email. I'll add a subject. Then I'll put in a message, which I'll say a message goes here. So I'm going to hit send. And we'll see that this uses Ajax to send this message. So let me inspect this to see if we're going to get any particular errors. So when we trigger the send, you will see that we have a post here, all this different information here, we have a response message has been sent. And it had a particular payload, we've decided to do that. And you can see that we have a dump in the name, the email, the subject and so on. So what I'm going to do instead of doing this, I'm going to get this particular information. And I'm going to email it to myself. So instead of a dumping, let me email this. So I'm going to use a particular function, which is WP mail, that is default to WordPress. And we're going to say two, let's just say we're going to send it to that email. The subject is already set. The message is set. The headers and attachments are what we might not need. So I'm going to just email this to myself. So let me save this, go back here, reload this. And let's try to add that information. So we'll just add, hit our send, we'll hit send says messages sent. Now I'm using local by flywheel. So let's check the mail traps that it has done to get our info. So we'll open up mail hug. And you will see that we have our subject is here. So it was trying to send that information. It's saying the message is from take a press that email the subject is this, the message body goes here. And you can see more of the information if you're really into that kind of thing. And you will see everything is as it should be. So instead of sending an email, you can actually decide to just post this information to a foreign server. So you would have to use the WP remote post function of WordPress. So in here, I would put this comma. I'm going to add a URL here. And I'll say this is my URL where this data is going. And then I can add arguments or args that will be used to send this data. So in here in the args, I could maybe add a header. I could let's say if I needed to authenticate what I am sending, so I can add it in the headers. I can add a body with all the text. So let me add a body, I wrap this in here. And then our body is going to have an array of data. So we can have the name subject and email copy this. I'm going to put them here. I'll put these quotations at the arrow signs at the end put the commas that I needed go back to the beginning, press this in here, go back to the beginning and clean this out. So this is just something I'm using with my editor so that I don't have to duplicate this. So we have our body, it's already in there. So all I need to do here is actually just press the URL that's going to receive our data. So I'm going to sign into it a grommat, which is a platform like Zapier. It allows you to do so many different things. I'm going to go to scenarios and I'm going to create a new scenario. And this scenario is going to be a web book. I'll click on web books right here and click continue. What it's going to do is that it requires you to add some particular information. So I'm going to add a web hook name and I'll call it a receive CF7 data. I'll not restrict any IPs. And it's going to give me a URL that I can ping. So I'm going to copy this right here. And I'm going to go and paste it inside my plugin. So we have the URL. We have the arguments. We have the remote post. So what we're going to do is add return at the end of the day when we are done posting all this information. So our web hook is going to be waiting for the information that's coming. And once we get the information, we'll be able to stretch it as it should be. So let me go back to my form right here. I reload it so that we don't have any issues. I'm going to say take a press two. Take a press two. I'll say give my email add API sending. That will be a subject and message is here we go. I'll hit send. Of course we get this working. The message here we are told the message is sent. Let's come back here to our API. Hit determine the data. Now let's go back to our front end. Let's add our take a press. We'll add take a press two. We'll add our email and other subject API sending. And then I'll say here we go as our email click send. And you'll see that this has been pinged. And that's why we're having this is successfully determined. So let's click OK. And it's going to refresh our data. So now web hook what we're going to do is we're going to add something else that's going to show us what we'll do. So and we'll add an iterator. And when I add an iterator, so when I add an iterator here and click on it, you'll see it says array and it's already picking information from the web hook that was triggered. So we have the name, the email subject and message. This would be a nice tool for you to look into if you're into automation and so on. I got to know it from a friend who was using this to automate their processes. So if you like the video, give it a thumbs up. If you have something to say, please leave it in the comments. Let me know how you're finding this video and other videos. And if you haven't subscribed, consider doing so because there's so much coming from this channel. Otherwise, enjoy your day.