PHP-and-MySQL/C4/Sending-Email-Part-1/English-timed

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

Contributors and Content Editors

Gyan, Pratik kamble, Sandhya.np14