0

Below is the HTML for the form im using.

<form action= "<?php echo get_template_directory_uri() . '/sendmail.php'; ?>" method="POST" id="contactForm">

    <div class="row alignleft infieldlabel">
        <p class="form_label">Name</p>
        <input type="text" id="name" name="yourname" value="" class="inputtext input_middle required">
    </div>

    <div class="space"></div>

    <div class="row alignleft infieldlabel">
        <p class="form_label">Email</p>
        <input type="text" id="email" name="email" value="" class="inputtext input_middle required">
    </div>

    <div class="clear"></div> 
    <p class="form_label">Select Subject</p>
    <div class="styled-select">
        <select id="subject">
            <option>Personal Injury</option>
            <option>Wrongful Death</option>
            <option>Litigation</option>
        </select>
    </div>  

    <div class="clear"></div>   

    <div class="row infieldlabel">
        <p class="form_label"><?php echo $eto_options["eto_textinput"];?></p>
        <textarea id="message" cols="30" rows="10" name="message" class="textarea textarea_middle required"></textarea>
    </div>

    <div class="row rowSubmit">
        <input type="submit" id="send" value="Send" class="contact_btnsubmit">                                
    </div>
</form>

Im using the following script to try and send the information. The email is just an example, in the actual use I had a correct email address.

$email = $_POST['[email protected]']; 

$to = $email; // email to send to...
$subject = $_POST["subject"];
$message = $_POST["message"];
$headers = 'From:' $_POST["email"] . "\r\n" .
    'Reply-To: Reply to email' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

Also i should note that when i hit the submit button on my form nothing happens, the page doesn't load or anything. Also this is in wordpress thus the random bit of php in the html.

11
  • Try closing input fields like /> Aug 22, 2013 at 2:17
  • This => $email = $_POST['[email protected]']; is invalid. It should be along the lines of $email = $_POST['email']; or $email = '[email protected]'; Aug 22, 2013 at 2:21
  • I tried closing out the input field with /> but it still wouldn't allow the form to send. When i click i still get no response. Aug 22, 2013 at 2:24
  • Does the form submit? If yes check @fred -ii-'s comment. Aug 22, 2013 at 2:26
  • @WilliamWilkerson Have you tried <form action= "sendmail.php" instead? It should work if both files are in the same folder. Otherwise, you may have to do something to the affect of <form action= "/wp-content/themes/your_theme/sendmail.php" --- also see my other comment. I helped someone with a similar problem a day or so ago. Aug 22, 2013 at 2:27

2 Answers 2

1

The problem was in the headers which threw me an error.

Your headers which contain Reply-To: Reply to <= 2x Reply statements

$headers = 'From:' $_POST["email"] . "\r\n" .
'Reply-To: Reply to email' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

Gave me the following error:

Parse error: syntax error, unexpected '$_POST' (T_VARIABLE) in...

Here is working code while using this in my test form:

<form action= "sendmail.php" method="POST" id="contactForm">

PHP

<?php

$email = $_POST['email']; 
$to = "[email protected]";
$subject = $_POST["subject"];
$message = $_POST["message"];
$headers = "From: $email" . "\r\n" .
"Reply-To: $email" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
mail($to, $subject, $message, $headers);

?>

FORM USED

NOTE: I changed <select id="subject"> to <select id="subject" name="subject">

That way, it will show up as the subject in your email which was not present in your form.

<form action= "sendmail.php" method="POST" id="contactForm">

<div class="row alignleft infieldlabel">
    <p class="form_label">Name</p>
    <input type="text" id="name" name="yourname" value="" class="inputtext input_middle required">
</div>

<div class="space"></div>

<div class="row alignleft infieldlabel">
    <p class="form_label">Email</p>
    <input type="text" id="email" name="email" value="" class="inputtext input_middle required">
</div>

<div class="clear"></div> 
 <p class="form_label">Select Subject</p>
<div class="styled-select">
    <select id="subject" name="subject">
       <option>Personal Injury</option>
       <option>Wrongful Death</option>
       <option>Litigation</option>
    </select>

</div>  


<div class="clear"></div>   

<div class="row infieldlabel">
   <p class="form_label"><?php echo $eto_options["eto_textinput"];?></p>
    <textarea id="message" cols="30" rows="10" name="message" class="textarea textarea_middle required"></textarea>
</div>

<div class="row rowSubmit">
<input type="submit" id="send" value="Send" class="contact_btnsubmit">                                

</div>
</form>
30
  • The form is still not sending to the script. Aug 22, 2013 at 2:42
  • @WilliamWilkerson I used this as the action in my test form <form action= "sendmail.php" method="POST" id="contactForm"> You obviously have a path issue to your sendmail.php Aug 22, 2013 at 2:43
  • if that's the case i should still get an error when the form tries to send to an incorrect url. The form doesn't even try to send. Aug 22, 2013 at 2:44
  • @WilliamWilkerson You would have gotten an error yes, with the present headers that you originally posted. Aug 22, 2013 at 2:47
  • I didn't get an error, the form makes no attempt to send the information. Aug 22, 2013 at 2:48
0

first try with following basic option and let me know whether this is working. copy paste this following code to your page.

<form action= "<?php echo get_template_directory_uri() . '/sendmail.php'; ?>" method="POST" id="contactForm">
    Test value:<input type="text" name="test_box" />
    <input type="submit" id="send" value="Send" class="contact_btnsubmit">
</form>
1
  • 1
    awesome then there is stupid error inside the form. so enter one div at a one time to above basic form and check whether the form is submitted. So eventually you would be able to narrow down where is the error. Also I noticed that subject select box does not hava a name
    – Viraths
    Aug 22, 2013 at 3:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.