I did some testing locally with your code. I think the problem is your form input names clashing with names reserved by WP. Also redirecting to success/error page should happen before get_header() to avoid any headers sent errors.
So, add some prefix/suffix to your input names, like so
<input type="text" name="my-name" placeholder="Your Name" class="input" id="name" required>
And move the submitting routine up,
if(isset($_POST['my-submit'])){
if(mail($to, $subject, $message, $headers)){
wp_redirect( home_url( '/email-success/' ) );
exit;
} else {
wp_redirect( home_url( '/email-failure/' ) );
exit;
}
}
get_header(); ?>
<!-- form html -->
Related Posts:
- How to fix ‘Notice: Undefined index:’ in PHP form action
- How to correctly submit a search form and display the result in an independent page
- Genesis – Customize search form
- Metabox repeating fields – radio buttons not saving correctly
- Inserting Gravity Form checkbox values into Advanced Custom Fields [closed]
- How to handle a custom form in wordpress to submit to another page?
- Has anyone tried putting PHP ActiveRecord on WordPress?
- Handling error states with admin_post
- On update to 3.04 site started recording accents as “á” and “á”, what to do?
- submit the form to same page
- Implement a multi-value input field where the number of entries is not limited
- Getting the dropdown menu to redirect to different pages?
- How do I let users upload files to a chosen location?
- woocommerce registration form with klaviyo(don’t work with current user)
- Custom Form Processing Issue
- Custom profile field with birthday. Troubles with
- WooCommerce/WordPress: how hide entire table form after submit (Admin Dashboard)?
- How to store data from multiple forms using ajax and php
- How to use $query->set with post__in?
- Ajax loaded form replaces form action with Ajax url
- prevent default not stopping page refresh. Passing form information to and from php with ajax in a wordpress site
- Custom search results page not working with empty search
- Modify HTML structure of fields in woocommerce checkout form
- Post + form + action + results on the same page
- Input data from email form not going to JSON file
- Styling my own password protected page, how to deal with wrong password?
- Search Query: how to construct a search string from two select elements?
- Login to wordpress by clicking a link and specifying usernaname and password in url
- How to show a ‘correct’ message after submit a form?
- Form Security: nonce vs. jQuery
- Trying do build a contact form
- User register hook is not working in woocomerce register form
- How to execute html code inside php?
- Can a page contain php code?
- How to send form data from WordPress (Meta Box) to an OData service?
- What is the alternative code to if (isset ($_POST) && !empty ($_POST) to avoid warnings?
- Why does my user not get added to the database on custom registration?
- How to add post meta in while loop?
- How to set cookies
- PHP Contact form
- Get wp_current_user_id using PHP and MySQL
- Adding Additional Variables on Menus Page
- PHP- Why is my contact form keep showing it is invalid? [closed]
- Simple php in wordpress widget [closed]
- form $_post action value gets truncated after it passes through two forms
- Pass important values server-side when processing form
- Adding data to custom wordpress database table
- Make a page (url) not cacheable [closed]
- Display multi-select box choices in a bullet list [closed]
- What should I write in the post action of this front end post form?
- Custom forms with HTML
- Contact form – problem with displaying message about sent mail
- Using Ajax to submit a form, and run a SQL Select query based on user input from the form
- WordPress Custom Form – Getting Query Vars, Weird Glitch?
- $_POST returning empty values
- Trying to update Woocommerce meta values
- How to send custom form submissions to WordPress Database?
- Custom PHP form needs refresh to load page correctly
- Form from within a page
- I want to retrieve the email or username data entered for password reset, but failed. how can I do it?
- How to change this ajax function to submit to the default wordpress content area instead of the custom field ‘seller notes’?
- Confuse between forms and tables
- wordpress contact form messages not sending although it saying they were sent successfully with this php code
- Using a PHP form, get the page title or any other element in the sent e-mail
- custom search query database in child theme
- Creating a WordPress addon for ContactForm7 submission (.XML file export)
- Using transients to store form notifications
- Insert data from form to database
- not able to access $_POST on backend profile update
- Custom Plugin Develoment, Form Action
- wordpress form action page not found
- Trouble with checked() for array of multiple checkboxes
- Custom HTML form using PHP – help with ajax/username validation
- Form direction to .php on localhost
- Form not working as it should in WordPress, but in a normal HTML site it does
- Submitting my form to the database and then redirecting to payment site
- Ajax call URL 404’ing when pushed to staging server
- Update only some custom user fields
- Passed variable gets undefined variable error on insert on next page
- How to set up an auto delete post?
- Dynamic form variables for post meta
- Trying to display user meta by “name” – not by “ID”
- Headers for Contact Form are wrong
- Using Nonce for my Form
- Trouble using wordpress functions in a pop-up modal form
- custom contact form no longer working (because of 3.2?)
- Correct Syntax for uploading files to custom directory in WordPress
- How to pass username into form that sends data to database
- HOW TO Insert Existing PHP Code to WOrdPress
- php inside HTML via shortcode? [closed]
- Where to put include php file?
- Redirect loop upon installation of my plugin
- Field validation strlen works in php7.4 fails 8.1 [closed]
- Embed PHP script into WP – what is the best way
- Preventing script injections in HTML form
- Bulk data save in custom table
- Can’t insert into a database wordpress
- Help with commenting system
- How to create a form that display license key (and email it to user) after the user enter their email and 10 digit code?
- Automatically populating a date parameter within a shortcode