1 00:00:00 --> 00:00:10 Welcome back. How do we fix this "'Sendmail from not set in php dot ini" error. 2 00:00:11 --> 00:00:17 We haven't determined who the email is from. 3 00:00:18 --> 00:00:22 We need to do this in order to send the email. 4 00:00:23 --> 00:00:28 We won't use something like a "from" parameter here. 5 00:00:29 --> 00:00:31 We need to send to specific headers. 6 00:00:32 --> 00:00:42 So here we create a "headers" variable which is not equal to something like "me @me.com" 7 00:00:43 --> 00:00:53 What we need to do is work with the standardised mail header and that is "From:" and a colon not semi colon and then we say for example "php academy" 8 00:00:54 --> 00:01:01 Or you could say something like "admin @php academy" and add ".com" if you like. 9 00:01:02 --> 00:01:07 I don't actually have that domain name but we'll just keep it as that. 10 00:01:08 --> 00:01:10 So "From: admin @phpacademy.com". 11 00:01:11 --> 00:01:17 Inside our mail we need to add another parameter now which is "headers". 12 00:01:18 --> 00:01:23 And now we come here and you can type "Alex" and here "This is a test!" 13 00:01:24 --> 00:01:26 Click on "Send me this" and we face another error. 14 00:01:27 --> 00:01:32 Now I am not actually running a mail server on my computer. 15 00:01:33 --> 00:01:45 If you don't want to run a mail server on your computer, google for at mail free mail server and this will install a mail server on your computer just like we are doing now running on a local host. 16 00:01:46 --> 00:01:53 And you will have a SMTP mail server running under local host. 17 00:01:54 --> 00:02:05 Now as I don't have a mail server, I will use my university email system which is the DNS or the "Domain Name Server" of my university email 18 00:02:06 --> 00:02:10 That's the way my email is sent through my university. 19 00:02:11 --> 00:02:21 If you know a specific DNS Server, if you have a domain name already, if you have a website you will know it or you will be able to find it, at least. 20 00:02:22 --> 00:02:26 You will be able to send an email through that. 21 00:02:27 --> 00:02:35 I know that my university email DNS server is "mailhost dot shef dot ac dot uk" because I'm in Sheffield university. 22 00:02:36 --> 00:02:40 So I need to incorporate this into my "php dot ini". 23 00:02:41 --> 00:02:45 And the best way to do this is to come here and setup our variables 24 00:02:46 --> 00:02:58 okay we need 2 - set SMTP in "php dot ini" 25 00:02:59 --> 00:03:04 And instead of opening up my "php dot ini" file ,I'll just use the "ini set" function. 26 00:03:05 --> 00:03:11 And the variable name is "SMTP". 27 00:03:12 --> 00:03:15 So we are editing this line inside our "php dot ini" file. 28 00:03:16 --> 00:03:19 And I type the mail host in there as the value. 29 00:03:20 --> 00:03:24 Here we just say echo "get ini" which gets a specific value. 30 00:03:25 --> 00:03:29 Next I'll say SMTP and that can just kill the script there. 31 00:03:30 --> 00:03:31 So we can see how this works. 32 00:03:32 --> 00:03:39 So if I say "Alex" and then "Test" and click on "Send me this". 33 00:03:40 --> 00:03:51 Oh! Sorry I have typed this completely wrong. Big mistake. That is "ini get" and lets refresh that. 34 00:03:52 --> 00:03:58 Okay we are basically setting our "SMTP" inside our "ini" file to "mail host dot shef dot ac dot uk". 35 00:03:59 --> 00:04:02 And then we will echo out the value of this. 36 00:04:03 --> 00:04:09 So this just tells me that that is set to "mail host dot shef dot ac dot uk". 37 00:04:10 --> 00:04:16 Presuming this mail host server or DNS server works, then the rest of the code will work. 38 00:04:17 --> 00:04:23 After sending our mail I'll just kill the page. 39 00:04:24 --> 00:04:27 Um.... no I won't . I'll just kill the page. 40 00:04:28 --> 00:04:35 Lets go back and say "Alex" and "This is a test". 41 00:04:36 --> 00:04:44 Just checking that everything is okay. We've got my "to", my "subject", my "headers" saying "From:admin@phpacademy.com". 42 00:04:45 --> 00:04:50 And our body in here and we are executing our mail function. 43 00:04:51 --> 00:04:57 So when I click "Send me this", nothing happens. We've got no errors so we can presume that everything has worked. 44 00:04:58 --> 00:05:08 If I come into my hotmail or my email and click on my INBOX, you can see that we've now got a mail from "admin @ phpacademy dot com". 45 00:05:09 --> 00:05:16 If we click on it, we have "Email from PHPAcademy" as our subject line that we had set here. 46 00:05:17 --> 00:05:21 And we have the email address that I specified from. 47 00:05:22 --> 00:05:26 You can put this as from Alex or from phpacademy. 48 00:05:27 --> 00:05:34 And then we have "This is an email from Alex" which is the name we gave inside the form here. 49 00:05:35 --> 00:05:39 And then we have 2 line breaks which are present - 1 and 2 50 00:05:40 --> 00:05:45 And "This is a test" which is the text I put in there. 51 00:05:46 --> 00:05:49 So that's a mail function by using my university's DNS mail server. 52 00:05:50 --> 00:05:54 Your INSP will have a DNS mail server. 53 00:05:55 --> 00:05:59 It may require authentication on which I will be completing the tutorial soon. 54 00:06:00 --> 00:06:08 So if this doesn't work for you watch that tutorial or just drop me an email or contact me through my youtube. 55 00:06:09 --> 00:06:12 OK so I hope that was useful to a lot of people. 56 00:06:13 --> 00:06:14 Please subscribe if you haven't already. 57 00:06:15 --> 00:06:20 Alright, thanks for watching. This is Evan Varkey dubbing for the Spoken Tutorial Project. Bye bye.