Placeholder Image

字幕表 動画を再生する

  • So let's talk about sending e mail directly from a PHP script.

  • So one of the nice things with PHP is that there is an actual function called the male function that allows you to send email directly from a PHP script so you can create a variable for the two.

  • A variable for the subject of variable for the message so on and so forth.

  • Basically, add that all to the male function, and then you can send off an email to whom ever you like.

  • So in order for this to work, you do have to have a local email server installed.

  • And so this is one of the reasons why I suggest people start with a shared hosting plan.

  • So if you go to go Daddy, your host gate or something like that, you pay your three or $5 per month.

  • They should have a local email server installed onto whatever host that you're using.

  • And so when you go to use the mail function, it will simply use that.

  • So this is something to remember with the male function is, it does have to have that local email server, and I have to say from experience, I prefer preferred not having to install email servers.

  • They could just be a pain in the butt.

  • So what's great about this is if you want to do things such as send out notifications now, the simple example that I'm going to show you is something that could be used again to send out notifications.

  • Let's say if there is an error or to have somebody log in their account, so on and so forth.

  • So basically, you could just have that notification gets sent off.

  • It goes through SMTP and then whether they're at their computer, their laptop or whether they have their watch, they can then get that email message and they can see whatever you're trying to tell them.

  • So it is important.

  • Understand what you going to be sending email that sending email can get complicated in order to send attachments and order, send things like pictures and that kind of thing.

  • That's that's a more complicated subject you can use.

  • Service is such as sending grid and actually use a male A p I to get next to a centigrade infrastructure, so that's one way you can do it.

  • But if all you're doing is you're looking for a very simple way just to be able to send out email notifications by simply using the male function built into PHP.

  • You can do that and again, if you're already on a shared postings server, then you don't have to worry about AP eyes or any of that type of stuff.

  • So with that, let's go over the computer, show you how this basic male function works, and I think you'll be pretty impressed.

  • It's a it's a pretty cool little function.

  • So this is just a simple script that I created called mail, not PHP.

  • Now it is important to understand with this script, not only am I using the script to actually send an email, but I did put a little trouble shooting routine within the script just to make sure this script actually ran in his updating.

  • So I have a little script of ran with the value of the variable time in here, and what this is going to do is after the email ascent, this will simply print on the screen that the script actually ran at the specific computer time.

  • So I do this type of thing again is a troubleshooting routine.

  • Just the fair.

  • Verify that the script is running.

  • So if it takes a little while to get the email, I know it's just delayed on the Internet.

  • It's not a problem with the script itself, but anyways, if we take a look at this again, as always, we open with a PHP tag.

  • This is PHP script, and then what we're going to do is we're going to go down and we're going to create variables for this email, and then we're going to feed those variables to the male function itself.

  • The first thing that we're going to do is we're gonna do dollar sign two equals.

  • And again, who is this email to the great part with this is this could be fed from a database.

  • This could be fed from a file.

  • This could be fed from an array, so this could loop through a four each, do this type of thing.

  • So right here I'm hard coding in who this is, too.

  • But again, this could be fed from a different variable S 02 again, as always, double quotation marks who it's too full, really.

  • Email address.

  • Close double quotation marks.

  • Semi colon, as always.

  • Then we're going to dio pound.

  • I'm sorry.

  • Dollar signs subject.

  • So this is gonna be subject equals.

  • And then So what is the subject of this email?

  • Pretty self extent explanatory.

  • Semi colon.

  • Then what is the message you're going to be so again when you do the message you're gonna have to think about is this gonna be printed out and text is it's gonna be printed out, isn't it?

  • Html You're gonna have to think about that kind of foreman madding stuff for this.

  • Basically, I'm just doing a basic, you know, test from PHP script.

  • Make my life easier.

  • But as you get more complicated with the messages, you are gonna have to think about the formatting again and with a semi colon, and then we're gonna do headers.

  • Now it's important.

  • Understand, with the male script is that this is all that's required, actually, kind of interesting.

  • We think about it.

  • In order for the male script to run, all you need is to all you need a subject, and all you need is message you don't actually need from from is kind of an add on that you put on later.

  • So if you send an email using just to subject a message, the from, well, actually just be your server address.

  • So that could be one thing.

  • From a security standpoint, if you don't put a from in there, is that it will, it will tell the person that you email, basically the from that will get auto filled in with the server address that the emails coming from.

  • So that's one thing you have to think about from a security standpoint.

  • Also, if you don't put in her from, it's more likely that spam filters will filter out the email coming through.

  • So even if this is your home, you're using Gmail or Hotmail or something like that.

  • If you don't, if you don't actually hard coded from and you might have issues with with spam filters blocking it so you can send these e mail messages with Halladay from again if you don't care, especially if this is like an internal email.

  • So you're just having you're just having to serve or tell you about notifications that's not going out to the wider world.

  • You may not care about the from ah, but from is nice again from a security standpoint from this anti spam standpoint and even one of the cool parts you can dio is for the from You can actually even have the from being not really email address and then used Gmail filters to dump dump like notifications into a specific into a specific folder.

  • So, you know, write anything from logs at failure dot com goes into this specific folder so you could do some interesting things there with with using from, but basically here, if you want to do it from you from where you're going to do is you're going to add headers.

  • So there's a lot of different things you can add with the headers.

  • All we're gonna add today is the from If you're more interested in headers, you go do some research.

  • So what we're gonna do is we're gonna create the headers were going to equal.

  • And so the header that we're going to do is we're gonna say from Colon and then a really email address that this is from and then in double quotation marks and semicolon obviously.

  • Now this this has nothing to do.

  • The time has nothing to do with this particular male script.

  • This doesn't allow male to function or anything like that.

  • I'm just adding this and here again as a little bit of a troubleshooting routine to make sure the script actually fires.

  • And then that's where we get to the male function.

  • So this is what the male function looks like and all you do with the male function that is, you do mail open parentheses, then you're gonna do dollar sign to variable for two.

  • The variable for subject.

  • The variable for message.

  • Obviously commas in between.

  • And again, this is all you have to put in.

  • You could actually end it right here if you wanted Thio, but we're going to add in the value for headers just so we get that from there.

  • Ahh.

  • And then we're going to close parentheses, and then we're going to do semi colon.

  • So this right here, this is what's required in orders in the mail.

  • And again, you can actually hard code everything in.

  • Instead of using variables here, you could actually type, you know, double quotation marks actually type all that information and here separated by commas.

  • But then that would just be ugly in a painting a bunch of trouble.

  • Shoot, Then what's gonna happen?

  • So this is going to fire.

  • So the males gonna fire it's going to send the email to for this question of Eli the computer guy.

  • And the thing is to understand, with this, it's gonna fire, and then there's gonna be nothing on the screen.

  • So this this just runs Unless you tell something to print or whatever, nothing's gonna be printed on the screen.

  • So what?

  • We're going to dio again?

  • This part is that troubleshooting routine is we're a new print and aggressively do double quotation marks.

  • Script ran and then we're going to give basically the computer time when it ran.

  • So this just tells me that it did run.

  • And then if I had at five, I refresh Then if this updates I know it fired again and again and again, Again, again, Stupid little troubleshooting routine s o.

  • If we go here, we go to silicon dough, Joe, forward slash male PHP and then we run and there we go.

  • This is all we see on the screen and again, it's important, Understand?

  • In the coding world, if you don't code something to happen it's gotta happen.

  • So if you want something printed on the screen or whatnot, you gotta you gotta have it actually printed out.

  • So all I wanted to see is that script ran, and then I get this computer time now for me.

  • I can't really read this computer.

  • This computer time doesn't actually mean a lot to me.

  • But what's important is if I refresh, I see that that time changes.

  • If I refresh, I see that I've changed.

  • So every time I have refreshed, I'm sending myself another email.

  • And so again, that's for me.

  • That's just a little trouble shoot routine there.

  • And then, if you look down at the bottom, I set myself on email a little bit earlier.

  • It is important.

  • Understand the emails going through the Internet, especially coming off the crappy little server under shared hosting plan.

  • It may take a couple of minutes to get to you, so just keep that in mind.

  • It's not sending the E mail to be clear.

  • Sending the email is instantaneous, but the email has to get from that server to your your email account, so that might take a couple of minutes.

  • The other thing to realize, especially if you're behind you look okay, so you see that just that just picked up to number two.

  • So I just got to e mails there.

  • The other thing to think about is if you're in a corporate world, so you have a really anti spam solution.

  • To be clear, if you have a real anti spam solution, this crap should be blocked really quick, because basically, this is kind of this is kind of like a phishing attack, right?

  • If you take a look at this, you go back to mail.

  • I mean, again, the thing like from I could do a TSH are at bank of japan dot com.

  • I could do like that's just that's just coated in there.

  • That's this.

  • So you understand.

  • I'm literally right now showing you how a fishing or spear phishing attack actually works.

  • And so there's some ways to prevent that type of thing.

  • And so that's what a corporate email account should block.

  • But yeah, uh, and so again.

  • So now down here, if you take a look.

  • You see, we've now got an eight e mails.

  • Now, I don't want to show you, uh, my particular email box.

  • Don't want to keep that a little bit protected.

  • So if we go, we can take a look at the E mail.

  • And this is the email that I received.

  • So this is the really mail that I received.

  • There's no modification here.

  • This is again.

  • This is just mail Apple's mail client.

  • Ah, and again for the email address we can see test at test dot com.

  • And that's what we could see to question at Eli, the computer guy dot com.

  • We can see the subject is this is a test and we can say See that this is a test from PHP script.

  • So all of this information just came right through.

  • Um, and that's basically how it works.

  • That's really all there is to the male PHP script, and this is where I say where a lot of people talk about one to be hackers.

  • I want to be a hacker, and this is why I always laugh at people is because this is what I say right here is if you understand how technology works.

  • If you understand how coding and all this works because hacking is just like it's just doing the exact same thing you would normally d'oh just slightly differently.

  • You know, I'm saying, like like doing this email right here.

  • I can either do a completely legitimate notification system for for a Web app or I could do a spear phishing attack.

  • The difference.

  • The difference is insanely trivial.

  • So that's why I laugh about those wannabe hackers.

  • That's really all there is with sending email with a male function and PHP.

  • The main thing that you have to remember is you do have to have that local email server installed if you want to be able to actually use this function again.

  • That's why I would suggest that you use a shared hosting plan at least to begin with again as your starting with P H B.

  • Pay a couple of bucks for shared hosting plan as you understand things more than you can do your own server, because this is the problem that you run into with a lot of folks is they try to build their own server from day one and then imagine.

  • Imagine as you're trying to learn this function, you're also trying to troubleshoot an email server, right?

  • This function is easy.

  • Email servers are not eso again.

  • That's if you ever wonder why I suggest certain things.

  • This is the type of thing that I say.

  • Learn how to do this on a shared hosting plan where you basically know what's gonna work and then build your own server.

  • Once you feel comfortable, the other thing again to with this is, since you're going to be sending e mails.

  • One thing to realize is that if you're having problems, it may not be that your code is the issue.

  • It may be again if you're trying to send e mails to yourself in a corporate environment.

  • To be clear, your corporate environment should block the hell out of this.

  • This shouldn't even get near your spam mail box.

  • Um, so if you're in a corporate environment, or maybe you've installed very heavy duty spam filters or something on your email, this type of thing may be blocked.

  • So that's one thing that you have to think about.

  • The other thing, too, is again.

  • Just look in your junk mail junk mail folder or spam because it may not get dumped into your normal inbox simply because it should be considered spam at the end of the day.

  • So these are the little things to consider.

  • If you look at this, there's the code you can copy and paste it.

  • If you're running the code, that time is coming up.

  • If everything is running properly, it seems you're running properly.

  • You're still having issues.

  • What you might want to do is just try, try a different email account.

  • Um, I'm using this.

  • Currently, I used your email.

  • So this does come through with female.

  • This does come through with other.

  • You know, Consumer great service is but again, one of those things just to think about at the end of the day.

  • And that's one reason to why a lot of people, when they do start to code, they decide to use something like send grids.

  • AP I.

  • So send grid is basically an e mail infrastructure for sending out massive emails.

  • One of the reasons people decide to use a the send grid a p I, and even pay for the Senate Great a p I versus using this, although this is completely free is send grid verifies their email servers are not on blacklists.

  • They verify you know, things to make sure that it's most likely that e mails will actually go through.

  • And that's kind of like those higher level things that you really have to start thinking about when you go out and develop Web APS versus simply just playing around and see what this technology will.

  • D'oh.

  • So that's really all there is to the male function and how to send email in PHP, And that's why it's important.

  • And don't don't Spearfish, Please don't Don't be a hacker.

  • Don't don't be a hacker.

  • Don't spear fish people, please.

So let's talk about sending e mail directly from a PHP script.

字幕と単語

動画の操作 ここで「動画」の調整と「字幕」の表示を設定することができます

B1 中級

PHP - 電子メールの送信 - mail() (PHP - Send Emails - mail())

  • 0 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語