1 00:00:00 --> 00:00:11 Hello and welcome. Today I will teach you how to create an email script particularly when you are registering a user onto a website. 2 00:00:12 --> 00:00:23 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. 3 00:00:24 --> 00:00:33 This will be in an HTML form in which you can write a subject and a message and send to a specified address. 4 00:00:34 --> 00:00:38 So, we will create an address variable. 5 00:00:39 --> 00:00:47 I will type my "hotmail" address here. 6 00:00:48 --> 00:00:54 You can see when I open up my current "hotmail" page and click on "Inbox", there are no emails here from me. 7 00:00:55 --> 00:01:04 There are no new emails at the moment. 8 00:01:05 --> 00:01:12 So This is the address in my address variable. I will rename the variable as "to" instead. 9 00:01:13 --> 00:01:16 We will use the mail function to send this out. 10 00:01:17 --> 00:01:20 We will have the from and subject in here. 11 00:01:21 --> 00:01:31 We will have a standard subject which says "Email from PHPAcademy". 12 00:01:32 --> 00:01:38 Next we need an HTML form that will submit. I will create a self submission one. 13 00:01:39 --> 00:01:53 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". 14 00:01:54 --> 00:01:58 The method is going to be POST. 15 00:01:59 --> 00:02:01 We will end our form here. 16 00:02:02 --> 00:02:09 The user can type in whatever they want to send to the email address that is specified here. 17 00:02:10 --> 00:02:17 Obviously you can take this into account. When creating a form, you could say you want to send to this particular address. 18 00:02:18 --> 00:02:26 This one will just be "send me an email" script - the email that you want to include in one of your website. 19 00:02:27 --> 00:02:30 Now we will have a "text" input. 20 00:02:31 --> 00:02:33 This will be the name of the person sending me the email. 21 00:02:34 --> 00:02:38 So you have type "text" whose name is "name" 22 00:02:39 --> 00:02:44 We'll have "max length" equal 20 for now. 23 00:02:45 --> 00:02:48 Underneath this we will create a text area. 24 00:02:49 --> 00:02:52 So I will type "textarea" and end it like that. 25 00:02:53 --> 00:02:58 Then we will name it as "message". 26 00:02:59 --> 00:03:03 We put a paragraph beginning and a paragraph ending here 27 00:03:04 --> 00:03:13 And down here we will create a submit button whose value equals "Send" 28 00:03:14 --> 00:03:16 Or.... "Send me this", okay? 29 00:03:17 --> 00:03:20 So if you come to our page and choose this page here 30 00:03:21 --> 00:03:24 this is the space for the name and this is the space for the message. 31 00:03:25 --> 00:03:30 So let me just put "Name:" in here and "Message:" in here. 32 00:03:31 --> 00:03:37 And this will look much better now. We have our name box and our message box. 33 00:03:38 --> 00:03:43 And when we click this button, the email will send. 34 00:03:44 --> 00:03:52 Okay so first of all inside our php code we need to check whether the submit button has been pressed. 35 00:03:53 --> 00:04:00 For that we have our "if" statement here in parenthesis and our curly brackets for our block if the condition is TRUE. 36 00:04:01 --> 00:04:04 The condition will be inside these parenthesis. 37 00:04:05 --> 00:04:14 The condition will be the post variable of the "submit" button. 38 00:04:15 --> 00:04:18 As long as the submit button has a value.... a spelling mistake.... 39 00:04:19 --> 00:04:29 So long as the submit button has been pressed, this will contain a value and that value is "Send me this". 40 00:04:30 --> 00:04:36 That would just mean that the form has been submitted because the button has been pressed. 41 00:04:37 --> 00:04:43 So inside here the first thing we need to do is get the data from the form. 42 00:04:44 --> 00:04:48 And that is the name of the person sending the email by submitting the form. 43 00:04:49 --> 00:04:55 And their name is contained within this form here - sorry this field here called "name". 44 00:04:56 --> 00:05:07 Also we have the message so we can easily duplicate this variable structure and say message in there. 45 00:05:08 --> 00:05:11 To test this out I'll say echo name. 46 00:05:12 --> 00:05:16 And I'll concatenate the message into that. 47 00:05:17 --> 00:05:20 Lets just test this out. Here I'll type "Alex". 48 00:05:21 --> 00:05:22 And here I will type "Hi there!" 49 00:05:23 --> 00:05:27 Click "Send me this" and we get "Alex" and "Hi there!" up there. 50 00:05:28 --> 00:05:32 Ok so, we know that the form data has been submitted correctly. 51 00:05:33 --> 00:05:41 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. 52 00:05:42 --> 00:05:44 So join me in the next part. Bye for now. 53 00:05:45 --> 00:05:50 This is Evan Varkey dubbing for the Spoken Tutorial Project.