✉️ PHP Contact Form Tutorial: Sending Email via XAMPP on Localhost

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone how is it going on I'm back again with a new tutorial in this tutorial I'm going to show how to create a contact from and then send email using PHP script from your Local Host so you don't need to upload the form in a live server you can do it using Local Host you just need xampp or any other software that provide a passy server first of all let's have a quick look at the demo of the project that we are going to do before that please subscribe to my channel if you're new to the channel so that you can get all the updates this is the form as you see here I'm using Local Host uh and I'm using xampp software so let's put some information here so it can take a few seconds yeah email sent now let's check the Gmail inbox should have a new email here yes we see a new email with test subject so that is what we're going to do without further Ado let's get started let's create the folder first I'm assuming you are using xampp server so we'll have to create the folder inside the htdocs let's do it so it is located inside the C drive and then xampp and then ht docs here let's create a new projects and let's name it contact form we'll open it using the vs code you can use uh any other code editor if you want whatever you have and here let's create the HTML F uh HTML file first where we'll put the form here let's put some boiler plate code using the shortcut and let's change the title to contact form and in inside the body let's put a container dip and here we will put the form with the method post because we will send the post method to the server and here in the action we'll have to put a PHP file let's name it process.php we'll have to create this file letter now let's put the fields one by one the first field will be the name so it will be a text field input text here the name attribute can be name or full name and let's put a placeholder here full name then let's copy it three times the second one will be email so here the name Will attribute will be email and the place folder will be email or enter email and here instead of text it will be email and the Third Field will be also a text field but it will be subject of the me of the of the email so here the placeholder enter subject now the fourth field will be a text area because it is the message that will be sent to the email so here the name can be message and the placeholder enter message all right now we'll have to uh put the submit button so input submit here the value can be sent and let's put a name submit all right okay now the HTML file is ready but it will look very ugly if you check it in the browser so you'll have to use some CSS because it is a PHP project I will not use M CSS so I will use instead I will use the bootstop so let's grab the Boop CN write bootstop cdn.com in the browser and let's copy the CSS part we'll just need the HTML code and let's put it inside the hattech all right so we have the Buddhist STP now we can use the predefined classes of budhist STP for the field input field we can use the class we can use the class name form control and we'll use some margin top four margin top four so let's copy this class for other fields here instead of form control we'll have to use a different class button button primary because it is a button now now we can check it how it looks so far in the browser so Local Host then contact form uh actually we'll have to exart the jamp control panel I forgot to do that so the AP server need to be start started all right it's looking good now the HTML code or the form is ready we'll have to send the data that will be put here to the email address so let's go to the process.php actually we'll have to create the process.php first process. PHP so here we you'll use the PHP tag first as you know whenever you'll write PHP cod we'll have to start the PHP tag so here we'll grab the data first but before that we'll have to check whether or not the form is submitted so we can do that using a global error variable called server inside the server the array key will be request method so if the request method is post so the if the form is submitted we will grab the data so for example the First Data will be the name so we can grab the data using the post error variable here the arror key will be full name as the name attribute was full name for the name as you see here and let's copy this um four times so the second field is email Third Field is subject and the fourth field is mze let's quickly have a look for the confirmation so message subject all good now we can send the data using the mail function it is a PHP function here the first argument is the recipient so two where the U the email will be sent the second field is the subject Third Field is the message itself and the fourth field is the heers heers basically the information about the standers now we can put this information into some variables so for the two I'll put my email address here you can put your own email address so that you can check and then subject so we already have subject here so also we have message here we just need the heater so let's create another variable heater and here we will just show the form email form and the email variable all right now let's change these two variables to subject mess and heers it will be actually heers okay now we'll put this mail function inside the if statement so that we can check whether or not the the email is delivered successfully so if mail function work correctly we'll display a message saying email sent otherwise else equal email sending fil let's check the output in the browser so let's put the information the test information here send and here we see a warning also email sending fi that is because we have not it was expected I expected this warning because I have not configured the SMTP on the php.ini file and the mail um send mail. file so we'll have to make some changes on those two files let's look at those two files the first one is PHP inii which is located inside the PHP folder here the file is php.ini there is the file so let's open it using notepad and let's search for mail function here we'll have to change few things first one is SMTP and SMTP Port sand mail form sand mail PA these four things need to be changed in this file I have uh save the information in a text file here so we can copy from here so first one smtp.gmail.com so we are using Gmail as our SMTP provider so here in SMTP it will be smtp.gmail.com and the port will be 587 and let's remove the semicolon from Sand mail from here we'll have to put our email address from where the email will be sent so my email address in this case is so I created this email address for testing purpose uh let's put here so you'll have to put your own email address here and here let's remove the semicolon from Sand mail path and let's copy the path from here so if you use Windows and if you if you installed jamp in the C drive the path will be look like this if you install jamp in another folder in that case you'll have to change the name of the drive so let's copy the path here okay php.ini file changes are done now we'll have to change the sand mail. file which is located inside the sand mail folder folder here we have sand mail. let's open it and here we'll have to change again the SMTP server then SMTP port and then username authentication username and authentication password these four things we'll have to change so let's again copy from here so SMTP gmail.com is the SMTP server Port is 587 then we have here authentication username which is the email address that you used in the php.ini file so let's copy the email address from there and then the password for this password we'll have to create a application password from our Google account so let's go to the Google account uh click on here on the on your profile then you should see manage your Google account let's click on here and then click on the security uh and then click on the twostep verification if you have already not added twep verification please add it before doing this so let's click on twep verification apption here I'll have to put my password now click next so here you should see an option called app password at the bottom of the page let's click here and click a app app name so in this case let's I have I have already have a app password name SMTP let's name it SMTP 2 and click create so you should see a password like this just copy the password click done and put this password in the authenication password and click save now let's check the form again okay we we'll have to do another thing we'll have to restart the server so click stop and then click Start now if you check uh you still see email sending fil I must have done something wrong in the code let's check the code yes in the heers instead of from it is form so let's fix it it should be from and also uh let's put a column and let's save it and let's check again in the browser now it should work fine yes email sent let's check the Gmail inbox there you go you see a new email here so that means everything is working fine let me know in the comments if you have any questions in your mind also if you enjoy the tutorial please hit like and please don't foret don't forget to subscribe thank you
Info
Channel: AUZ Tutorials
Views: 16,822
Rating: undefined out of 5
Keywords: how to send mail from localhost xampp using gmail, php send email, send email using php, send email using phpmailer, how to send mail from localhost in php using xampp, sendmail on localhost, use sendmail on localhost, how to send mail from localhost, mail on localhost, how to send mail using php from localhost, send email from localhost using xampp, how to send email using php, send email using php from localhost xampp, how to send email in php from localhost xampp
Id: aB6iovBcAAQ
Channel Id: undefined
Length: 15min 1sec (901 seconds)
Published: Sat Oct 07 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.