In this video we are going to create a simple contact form. you can see here at the moment we just got to text fields and a text area the idea here is these are filled out the form click Submit and this is sent through to an email address with the relevant data.
Learn PHP Programming from Scratch: https://www.simplilearn.com/web-app-and-programming/learn-php-programming-from-scratch?utm_campaign=how-to-create-form-iykJl6iXCao&utm_medium=SC&utm_source=youtube
let’s go ahead and type in my name, is hoping a valid email address, now this form field here will be invalidated so the user will have to provide a valid email address and also message as well, we go ahead and click on Submit, has been submitted we’ve got this confirmation message thanks for contacting us an important point here is that we can’t then go ahead and refresh the page to resend it because essentially seeing this sent variable hear, about that in a moment they have now received an email from Alex from PHP academy he can we talk which is the email address that we supplied and we’ve also got the message in here, now the good thing about this is we’ve supplied the email address that’s been provided and we’ve put this into the From field so we can basically hit reply and this will then send us back to the email address that the user has provided. So essentially just a really quick way to get a contact form submission sent you an email address and then the ability to go ahead and reply email directly. so that’s basically it let’s just quickly take a look at what happens when we don’t enter anything which is here we have a message here so error message that the name email messages are required to let’s go ahead and fill the end but just so Alex in the email field for example and then just hello in here when I click Submit we get that validate email address so we validating this field here many other good thing about this is that you noticed that these form fields have retained their values we’ve refresh the page but we haven’t actually got rid of these values which browsers will do by the fall so we’re keeping these values as well so we’ll be discussing all these points and creating a basic contact form so in the next part will be starting to write the mark-up and then we’ll look at some PHP code.
So watch the full video to learn more.
For more updates on courses and tips follow us on:
– Facebook : https://www.facebook.com/Simplilearn
– Twitter: https://twitter.com/simplilearn
Get the android app: http://bit.ly/1WlVo4u
Get the iOS app: http://apple.co/1HIO5J0
Amazon Auto Links: No products found.
Great job man! Really appreciate this.
nicely explained and very helpful for learning php, but when i tried this, i got no errors and the message that the message was sent, but i don’t receive it in my inbox. Any help guys?
This is a great video! For some reason I am getting this error: {“code”:”MethodNotAllowedError”,”message”:”POST is not allowed”} when I am clicking the submit button. Any ideas?
Nice tutorial. Easy to understand.
beautiful lesson
I feel like you could do some of the form validation checking in JavaScript so it could update as the user types in the inputs, in real time.
Your voice sounds like Benji from mission: impossible
That’s nice
Check The code above video
< ?php if(empty($_POST) === false) { $errors = array(); $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; if(empty($name) === true || empty($email) === true || empty($message) === true) { $errors[] = 'name, email and message are required!'; } else { if(filter_var($email, FILTER_VALIDATE_EMAIL) === false) { $errors[] = 'Not valid email'; } if(ctype_alpha($name) === false) { $errors[] = 'name contain letters!'; } } if(empty($errors) === true) { mail('exampl@gmail.com','contact form',$message, 'From: '.$email); header('Location: contact.php?sent'); exit(); } } ?>
< !DOCTYPE html>
< ?php if(isset($_GET['sent']) === true) { echo '
Thank you for contacting us‘;
}
else
{
if(empty($errors) === false)
{
echo ‘
‘;- ‘,$error,’
foreach($errors as $error)
{
echo ‘
‘;
}
echo ‘
‘;
}
?>
Excellent tutorial.
Gmail does not accept Port 25 from a residential IP. Anybody have any ideas how to send myself mail via setting up SMTP with MAMP Pro?
Whenever I refresh the page it wants to submit the form again, I did some online research and people mentioned to use post/redirect/get method. However I didn’t see you run into this problem at all?
Hi i want to ask how is called the video for configuring apache and php .
Thanks for the video it was great !
this is From Codecours
Thanks again buddy! Great tutorial as always!
Great tutorial, thank you! Has anyone received an answer to your questions about not receiving emails? I have the same problem, everything seems to be working perfect, but the email is not coming…
hello buddy awsome video thanks a lot ,but the problem is i did not recieve mail in my inbox,please help
Hi dear sir I have this error all time why please help me
Notice: Use of undefined constant ture – assumed ‘ture’ in C:xampphtdocsformssecond topicmail.php on line 10
Ugh why would you use Notepad.
Hi, I completed your contact form and everything worked right up to when I put in the very last bit of php code, then everything went south. All of the code appeared on the web page after I refreshed. Not sure what happened there, maybe I need the server side code, but was wondering if that is what happens when you do not have the server side code. I also found another slight problem in your code as far as the name is concerned. An error shows up when you try to put in your surname, it says it doesn’t accept spaces in between your first name and your second name. Great video, but would very much like to iron out these two problems I have. Thanks.
This is a wonderful video and my form works perfectly… except for one thing. One of the form fields is “Name” and I would like to get the name as well as the subject, email and message. I’ve tried adding $firstname to the ‘mail’ area, but then the form won’t send. Would appreciate your input on this. Thanks!
very nice and clean tutorial!!! What about security?
THANK YOU SO MUCH you help me alot, actually you save my life 🙂 thank you really really.
how to put it to website?
Alex did that error code at my html about my form and the document suddenly stop responding in page
Where is the tutorial on linking the email? Thank you! Great tutorial!
Can you leave the link for a video tutorial on configuring smtp in xampp?
Anybody figure out how to send $name? As a novice, this is a stumbling block. I’ll take any quick fix. Cheers
Great tutorial! Is there a download link for the form?
Hi, thanks for the help. Everything works but I don’t receive the email. Is there something within XAMPP that I need to set up or activate in order for the email to be received? How do I set up what is mentioned at 23:10 on XAMPP, where’s the video that he mentions? Thanks a lot.
Hey I am trying to code a simple contact form like the one in your video but the message doesn’t seem to be sending. Someone saw my code and said the reason it is not sending is because there is no smtp server name, password, port number and username. In all of the tutorials i have watch i have never seen an instructor enter those info in there code and there messages send with success can you please explain why. I am a very confused newbie.
Hi everyone. I had a problem of not receiving the email. sending from the site was successful.. i sort of changed the code and it works (with some deformities on the receiving side). Maybe someone can perfect it???
here are the changes (in send main line the last two parameter, you tube wont let me post the whole code)
//send email
$_POST[‘message’], $_POST[’email’]
It is showing my code in the browser i have index.php and everything is correct. Any help?
thank you dude it’s help me a lot keep up the good work.
nice tutorial buddy
wtf Alex is everywhere! xD
This is one of the better tutorials. Unfortunately its very blurry and its very hard to view some of he smaller characters. Are there download files to check the code?
Thank you so much for this lesson !
I did exactly what you did but i don’t receive an email when i submit the contactform.. Please help
Great Tutorial and Thank you. Did I miss something or did you not mail the variable $name? Your mail() function only has the $message and $email variables in it. I’m not trying to nitpick just want to make sure I understood everything.
Hello! Can you help me, because i didn’t receive the email in my inbox.
Pease help!
Thank you for the nice tutorial! One little question: when I write something like “ü” or “ß” and send this, i will receive something like “ßßßÔ. How can add the UTF-8 encoding? Thanks!
Awesome video!
Just some questions: how do I upload this correctly to my ftp root directory/webhost so that it works correct?
So I can actually have everything in one file ? should I then name it .php? I tried something similar but I had to have a index.php to my form.php. Didn’t work naturally got the WSOD
Very well explained, tks