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

From Script | Spoken-Tutorial
Revision as of 20:49, 1 December 2012 by Pravin1389 (Talk | contribs)

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

Contributors and Content Editors

Chandrika, Pravin1389