Failing to submit a very simple form with wp_mail
-
Hi people…
I create a custom page-template for my contact page, with the following code:
<?php // Template Name: Contact Page if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) { $to = '[email protected]'; $subject = $_POST['subject']; $headers = 'Reply-to: ' . $_POST['name'] . ' <' . $_POST['email'] . '>' . ':'; $message = $_POST['message']; wp_mail($to,$subject,$message,$headers); } ?> <?php get_header();?> <div id="content" style="padding:0"> <form id="contact-form" method="post" action="<?php the_permalink();?>"> <label for="name">Name:</label> <input type="text" id="name" name="name" value="" placeholder="Tu nombre" autofocus="autofocus" required="required" /> <label for="email">Email:</label> <input type="email" id="email" name="email" value="" placeholder="[email protected]" required="required" /> <label for="subject">Subject:</label> <select id="subject" name="subject" required="required"> <option>Option 1</option> <option>Option 2</option> <option>Option 3</option> </select> <label for="message">Message:</label> <textarea id="message" name="message" placeholder="Write your message here, please." required="required" maxlength="99"></textarea> <input type="submit" value="SEND!" id="submit" class="btn" /> </form> </div> <?php get_footer();?>
I try and try, but in all my tests the submit button send me to an error page, with a title “Page not found”.
I rly want to use pure wp functions without the need of plugins, to have the maximum control over my site. And also prefer the code readable and clean.
I spent a whole week looking for docs and tuts but the use of wp_mail seems not too clear to me…
Please can someone tell me what is wrong with my code above?
Thanks!
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Failing to submit a very simple form with wp_mail’ is closed to new replies.