0

I am using WP_MAIL to submit a contact form from my wordpress website. I have two files, one for the HTML form and one for the PHP function. When i hit submit however the function doesn't seem to fire. I have tested wp_mail and it is working. The strange thing is, this function was workign on Monday and now it is not.

Here is a basic version of my HTML and the full PHP function.

<form class="form-horizontal" action="" method="POST">
<input type="text" class="form-control" name ="name" placeholder="your name">
<input type="text" class="form-control" name ="email" placeholder="your email">
<input type="text" class="form-control" name ="number" placeholder="your number">

</form>
<?php
add_action('wp', 'send_my_awesome_form');

function send_my_awesome_form(){

if (!isset($_POST['submit'])) { return; }

// get the info from the from the form
$form = array();
$form['name'] = $_POST['name'];
$form['number'] = $_POST['number'];
$form['email'] = $_POST['email'];

// Build the message
$message  = "Name :" . $form['name'] ."\n";
$message .= "Number :" . $form['number'] ."\n";
$message .= "Email :" . $form['email'] ."\n";


//set the form headers
$headers = 'From: The Website';

// The email subject
$subject = 'Booking Request';

// Who are we going to send this form too
$send_to = '[email protected]';

if (wp_mail( $send_to, $subject, $message, $headers ) ) {
     wp_redirect('http://www.urltogoto.com'); exit;
 }

}
?>
2
  • review everything you changed since monday. are you using any kind of version control? Commented Oct 14, 2015 at 10:49
  • I did, it took me seconds to review it and then remembered that I didnt work on Tuesday lol. None the less, Im now getting a white screen when I click submit an my console shows a 404 error. Commented Oct 14, 2015 at 10:52

2 Answers 2

1

Try renaming (for example temporarily prefixing) your form field names. The name "name" (amongst others) is reserved in WordPress causing a 404.

Sign up to request clarification or add additional context in comments.

Comments

0

You must take one by one php line to check, if you dont see any errors. you can try this first comment this line //if (!isset($_POST['submit'])) { return; }. if you will be redirected to http://www.urltogoto.com then you have an problem with your if statement.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.