php - 带有选择字段问题的联系表

标签 php html forms

我的联系表有一些问题,我尝试了很多解决方案,但仍然没有用。

我有一个包含基本输入和选择字段的基本联系表。除了我选择的字段中的数据外,所有字段都通过电子邮件发送。

这是我的 HTML 表单:

<section class="section-signup bg-faded mt80">
                      <div class="container">
                        <div class="row">
                            
                              <h3 class="text-xs-center">Je veux devenir un point de vente</h3>
                              <p class="subform m-b-3">Merci de préciser si vous êtes une entreprise, un courtier, un investisseur, un professionnel ou autre</p>
                                <div class="form-bottom contact-form">
                              <form role="form" action="contact.php" method="post">
                                <div class="form-group col-md-4">
                                  <label for="email_expediteur">Votre adresse e-mail :</label>
                                    <input type="text" name="email" placeholder="Email..." class="contact-email form-control" id="contact-email">
                                  </div>
                                  <div class="form-group col-md-4">
                                    <label for="email_expediteur">Sujet :</label>
                                    <input type="text" name="subject" placeholder="Sujet..." class="contact-subject form-control" id="contact-subject">
                                  </div>
                                  <div class="col-md-4 form-group">
                                        <label for="jesuis">Je suis : </label>
                                        <select class="form-control" name="jesuis">
                                          <option value="">Selectionnez...</option>
                                          <option value="entreprise">Une entreprise</option>
                                          <option value="courtier">Un courtier</option>
                                          <option value="investisseur">Un investisseur</option>
                                          <option value="professionnel">Un professionnel</option>
                                          <option value="autre">Autre</option>
                                        </select>
                                </div>  
                                  <div class="col-md-12 form-group">
                                    <label for="contact-message">Message :</label>
                                    <textarea name="message" placeholder="Message..." class="contact-message form-control" id="contact-message"></textarea>
                                  </div>
                                  <div class="col-md-12 form-group">
                                    <label for="contact-antispam">Question Antispam : 7 + 5 = ?</label>
                                    <input type="text" name="antispam" placeholder="Votre réponse..." class="contact-antispam form-control" id="contact-antispam">
                                  </div>
                                  <div class="col-md-6 col-md-offset-3 form-group centered">
                                  <button type="submit" class="btn">Envoyer</button>
                                  </div>  
                              </form>
                            </div>
                            
                        </div>
                    </div>      
                    
                </section>

这是我的 contact.php :

<?php

// Email address verification
function isEmail($email) {
  return filter_var($email, FILTER_VALIDATE_EMAIL);
}

if($_POST) {

    // Enter the email where you want to receive the message
    $emailTo = 'info@yachtbox.net';

    $clientEmail = addslashes(trim($_POST['email']));
    $subject = addslashes(trim($_POST['subject']));
    $message = addslashes(trim($_POST['message']));
    $antispam = addslashes(trim($_POST['antispam']));
    $jesuis = addslashes(trim($_POST['jesuis']));

    $array = array('emailMessage' => '', 'subjectMessage' => '', 'messageMessage' => '', 'antispamMessage' => '', 'jesuisMessage' =>'');

    if(!isEmail($clientEmail)) {
        $array['emailMessage'] = 'Email Invalide';
    }
    if($subject == '') {
        $array['subjectMessage'] = 'Sujet manquant';
    }
    if($message == '') {
        $array['messageMessage'] = 'Message manquant';
    }
    if($antispam != '12') {
      $array['antispamMessage'] = 'Mauvaise réponse';
    }
    if($jesuis == '') {
        $array['jesuisMessage'] = 'Merci de préciser si vous êtes une entreprise, un courtier, un investisseur, un professionnel ou autre';
    }
    if(isEmail($clientEmail) && $subject != '' && $message != '' && $antispam == '12' && $jesuis != '') {
        // Send email
    $headers = "From: " . $clientEmail . " <" . $clientEmail . ">" . "\r\n" . "Reply-To: " . $clientEmail;
    mail($emailTo, $subject . " (Formulaire de contact MUST Assurances)", $message, $headers, $jesuis);
    }
    

    echo json_encode($array);

}

?>

你有什么想法吗?

干杯。

洛伊克

最佳答案

$message = "Je suis un(e) ".$jesuis." ".$message;
mail($emailTo, $subject . " (Formulaire de contact MUST Assurances)", $message, $headers);

您的第 5 个参数没有意义。

关于php - 带有选择字段问题的联系表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37416409/

相关文章:

php - 发生事情时如何使用php脚本,ajax?

jQuery mouseenter 和 z-index 不能正常工作

javascript - 提交表格并在不同的页面上阅读

javascript - 向网页提交多个表单

php - 更新级联是否仅用于非规范化表?

php - 在 Linux 上设置 SVN/LAMP/测试服务器,从哪里开始?

php - 如何在 php 中获取超过 x 行的特定列值?

javascript - 获取从类 *not* style 属性继承的元素样式

html - Unity Webgl html 容器 : how to "stretch" width window based on browser width?

vba - 通过导航表单传递查询表达式