Hello and welcome. Today I will teach you how to create an email script particularly when you are registering a user onto a website.
How do you send them an email confirming that they have registered. I will do that partly by creating a script - a "Send me an email" script.
This will be in an HTML form in which you can write a subject and a message and send to a specified address.
So, we will create an address variable.
I will type my "hotmail" address here.
You can see when I open up my current "hotmail" page and click on "Inbox", there are no emails here from me.
There are no new emails at the moment.
So This is the address in my address variable. I will rename the variable as "to" instead.
We will use the mail function to send this out.
We will have the from and subject in here.
We will have a standard subject which says "Email from PHPAcademy".
Next we need an HTML form that will submit. I will create a self submission one.
So lets put some html code here. I will have a form here which will submit to this page with "send me an email dot php".
The method is going to be POST.
We will end our form here.
The user can type in whatever they want to send to the email address that is specified here.
Obviously you can take this into account. When creating a form, you could say you want to send to this particular address.
This one will just be "send me an email" script - the email that you want to include in one of your website.
Now we will have a "text" input.
This will be the name of the person sending me the email.
So you have type "text" whose name is "name"
We'll have "max length" equal 20 for now.
Underneath this we will create a text area.
So I will type "textarea" and end it like that.
Then we will name it as "message".
We put a paragraph beginning and a paragraph ending here
And down here we will create a submit button whose value equals "Send"
Or.... "Send me this", okay?
So if you come to our page and choose this page here
this is the space for the name and this is the space for the message.
So let me just put "Name:" in here and "Message:" in here.
And this will look much better now. We have our name box and our message box.
And when we click this button, the email will send.
Okay so first of all inside our php code we need to check whether the submit button has been pressed.
For that we have our "if" statement here in parenthesis and our curly brackets for our block if the condition is TRUE.
The condition will be inside these parenthesis.
The condition will be the post variable of the "submit" button.
As long as the submit button has a value.... a spelling mistake....
So long as the submit button has been pressed, this will contain a value and that value is "Send me this".
That would just mean that the form has been submitted because the button has been pressed.
So inside here the first thing we need to do is get the data from the form.
And that is the name of the person sending the email by submitting the form.
And their name is contained within this form here - sorry this field here called "name".
Also we have the message so we can easily duplicate this variable structure and say message in there.
To test this out I'll say echo name.
And I'll concatenate the message into that.
Lets just test this out. Here I'll type "Alex".
And here I will type "Hi there!"
Click "Send me this" and we get "Alex" and "Hi there!" up there.
Ok so, we know that the form data has been submitted correctly.
In the next part of this video we will learn how to validate this and eventually send this mail to the user specified in this email-id here.
So join me in the next part. Bye for now.
This is Evan Varkey dubbing for the Spoken Tutorial Project.