doudui2229 2013-08-22 02:12
浏览 25
已采纳

形式信息从形式不发送

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['mail@example.com']; 

$to = $email; // email to send to...
$subject = $_POST["subject"];
$message = $_POST["message"];
$headers = 'From:' $_POST["email"] . "
" .
    'Reply-To: Reply to email' . "
" .
    '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.

  • 写回答

2条回答 默认 最新

  • douan3182 2013-08-22 02:40
    关注

    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"] . "
    " .
    'Reply-To: Reply to email' . "
    " .
    '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@example.com";
    $subject = $_POST["subject"];
    $message = $_POST["message"];
    $headers = "From: $email" . "
    " .
    "Reply-To: $email" . "
    " .
    "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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来