形式信息从形式不发送

时间:2013-08-22 02:12:38

标签: html wordpress html-form php

以下是我正在使用的表单的HTML。

<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>

我使用以下脚本尝试发送信息。电子邮件只是一个例子,在实际使用中我有一个正确的电子邮件地址。

$email = $_POST['mail@example.com']; 

$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);
?>

另外我应该注意,当我点击我的表单上的提交按钮没有任何反应,页面没有加载或任何东西。这也是在wordpress中因此是html中php的随机位。

2 个答案:

答案 0 :(得分:1)

问题出现在标题中,这让我误以为。

您的标题包含Reply-To: Reply to&lt; = 2x回复语句

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

给我以下错误:

  

解析错误:语法错误,意外的'$ _POST'(T_VARIABLE)...

以下是我在测试表单中使用此代码时的工作代码:

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

PHP

<?php

$email = $_POST['email']; 
$to = "email@example.com";
$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

注意:我将<select id="subject">更改为<select id="subject" name="subject">

这样,它会在您的电子邮件中显示为您表单中没有的主题。

<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>

答案 1 :(得分:0)

首先尝试使用以下基本选项,然后让我知道这是否有效。将以下代码粘贴到您的网页上。

<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>