| | #1 |
| Active Warrior Join Date: 2009
Posts: 95
Thanks: 111
Thanked 8 Times in 7 Posts
| <?php if(isset($_POST['submit'])) { $myemail = "your-email-address@here.com"; $subject = $_POST['subject']; $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $headers = "From:Contact Form <$myemail>\r\n"; $headers .= "Reply-To: $name <$email>\r\n"; echo "Your message has been sent successfully!"; mail($myemail, $subject, $message, $headers); } else { echo "An error occurred during the submission of your message"; } ?> Anyone have any suggestions on what code I could add to make the fields in the above contact form required? Thanks! |
| | |
| | |
| | #2 |
| Howdy War Room Member Join Date: 2008 Location: England
Posts: 683
Thanks: 103
Thanked 150 Times in 124 Posts
|
Use javascript to check form field validation https://www.w3schools.com/js/js_validation.asp or PHP https://www.w3schools.com/php/php_form_validation.asp |
| | |
| The Following User Says Thank You to Valdor Kiebach For This Useful Post: |
| | #3 | |
| Active Warrior Join Date: 2009
Posts: 95
Thanks: 111
Thanked 8 Times in 7 Posts
|
Now, I'm trying to figure out how to combine the following: https://www.w3schools.com/php/php_form_required.asp With the php code shown in the op, whereas the form mail gets sent only after all required fields have been filled? Thanks again! | |
| | ||
| | |
| | #4 |
| ANJAN KUMAR DHALI Join Date: 2014 Location: Bangladesh
Posts: 73
Thanks: 3
Thanked 18 Times in 12 Posts
|
please checkout Create Contact form using php mysql |
| | |
| | |
| The Following User Says Thank You to ANJANBD For This Useful Post: |
| | #5 |
| Active Warrior Join Date: 2009
Posts: 95
Thanks: 111
Thanked 8 Times in 7 Posts
| Which brings the next question, I'm wondering that rather than just having the message "Your message has been sent successfully!" written as shown in the op, I rather that it be taken to a thank you page after the form submission. How to do so? Thanks again in advance! |
| | |
| | |
| Bookmarks |
| Tags |
| contact, fields, form, making, required |
| |