Okay so we have created our HTML form here and determined that the data has been processed through the POST variable when our form has been submitted.
The next thing I'll do is just check some conditions on this just for the sake of the tutorial
I'll say if the string length...
No - first of all I'll check for existence - So if name and message
This is just saying does this exist and does this exist because as long as they do, they will always have a true value.
And we are using the "and" operator here which says "Is this true AND is this true".
If this is TRUE, we will execute the code here.
Otherwise I want to kill this script and I'll say "You must enter a name and message"
And maybe just underline that for effect.
And inside our block of the code - if this is TRUE we will perform another check.
So here we have checked with an existence check
And now here what we will do is run another check.
How can I word it? I'll do a length check. So I will comment this as length check.
We will say name or rather the length of the string using the string-length function.
We check if string-length function of name is greater - no, lesser or equal to our max length which is '20'. We can have any number here.
And the string-length of message is lesser or equal to 300 characters. Obviously, you can have any number here, too.
Then we will execute this block of code.
Otherwise we will say "Max length for name is 20 and max length for message is 300".
Obviously a good thing to do is to store 300 and 20 in variables
Lets set them here. So you can say "namelen" equals 20 and you can say "messagelen" equals to 300.
Then what you can do is incorporate this here. So "namelen" there.... oooops so "namelen" there
And here you could say - oh! lets put that back - and here you can say "messagelen".
Down here, too, replace these. So these will be dynamically replaced if you are performing the check.
So here you say "messagelen".
So let's test this out. The "namelen" is maximum 20 characters so here we can only enter a maximum of 20 characters. So, Alex here.
In message, I'll enter some text more than 300 characters long. I'll just copy paste this along.
That should be more than 300 characters now.
So if I click on "Send me this" button, we get the message - The max length of the name is 20... that's the variable that's been put here
And the maximum length for this is 300; that's another variable that's taken from here.
We are taking the check and echoing out this variable as well.
Presuming that everything is okay we are going to get the email sent to the user.
I keep stressing this - its the address here and we've already got our subject line here.
Perhaps we could bring these down here; there is no point setting a variable if the email is not ready to send.
So this is our setup variables . We also have the...
We could say "from" but this is similar to email address.
So we got the "name" already and all we really need is the "message" which again is here.
We also need some header information which I'll show you soon but I'll head straight to the "mail function".
The "mail function" is as follows - mail and the first variable you need to include is who this message is "to". So I'll type "to".
Then the subject of the email which is just "subject".
Its here. Then we have the body of the email so "body".
Here we will say body equals the following - This is an email from "name". So we have included the name inside the body of the email.
Then just use backslash n which is new line - so that's 2 new lines.
Next we will echo out the message which will be included in this.
So our body consists of a generic message here, the user's name that we have processed in the form and then two new lines and next we have entered the message that has been entered in our form here. Okay?
So lets get rid of these.
That looks good to go.
As a mail function you may think how that would work but sending email php is quiet easy.
But when we do actually send the email, we can see that there are some problems.
We have got a warning - the mail function "send mail from" is not set in php dot ini or custom "From:" header missing.
I have not set the "send mail from" in my ini. I missed that. So I'll do it manually.
After we have done this, we'll run into another error as well.
I will teach you how to fix it but in the next part of the video.
In the next part we'll deal with anymore errors we get after that.
So join me in the next part. Bye for now. This is Evan Varkey dubbing for the Spoken Tutorial Project.