【问题标题】:Too many redirects PHP contact form太多重定向 PHP 联系表单
【发布时间】:2020-03-24 12:52:35
【问题描述】:

我的网站说重定向太多,当您尝试提交要邮寄到电子邮件的表单时会发生这种情况。两者之间的联系是正确的。

表格代码:

<section class="linksMain">
      <div class="form-style-5">
        <form action="../php/main/contact1.php" method="post">
        <fieldset>
          <legend>Personelijke informatie</legend>
          <input class="form" type="text" name="field1" placeholder="Je naam *">
          <input class="form" type="email" name="field2" placeholder="Je email *">
          <input class="form" type="text" name="field3" placeholder="Onderwerp">
          <label for="job">Categorie</label>
          <select id="job" name="field4">
              <option value="School">School</option>
              <option value="Stage">Stage</option>
              <option value="Media">Media INN</option>
              <option value="Copt">Copyright</option>
              <option value="Opdracht">Opdracht</option>
              <option value="Opdracht">VKG</option>
              <option value="Opdracht">Privé</option>
              <option value="other_indoor">Anders</option>
            </optgroup>
          </select>      
        </fieldset>
        <fieldset>
          <legend>Bericht</legend>
          <textarea class="form" name="field5" placeholder="Over jezelf"></textarea>
        </fieldset>
        <input type="submit" value="Verstuur" />
        </form>
      </div>    
    </section>

PHP 代码:

#This sends emails to inbox@driekvandermeulen.nl, the filler of the email comes from a form in main/contact.php

$name = $POST['field1'];
$email = $POST['field2'];
$subject = $POST['field3'];
$category = $POST['field4'];
$message = $POST['field5'];

$mailTo = "inbox@driekvandermeulen.nl";
$headers = "From:".$mailFrom;
$txt = "Je hebt een email gekregen van".$name.".\n\n".$message;

mail($mailTo, $subject, $category, $headers);
header("Location: contact1.php?mailsend");

【问题讨论】:

    标签: php html forms email redirect


    【解决方案1】:

    您要更改为header("Location: contact1.php?mailsend"); 的标头位置将触发重定向。等等。您必须捕获 ?mailsend 查询并检查是否通过以停止代码。

    if ($_GET['mailsend'] == false) {
      mail($mailTo, $subject, $category, $headers);
      header("Location: contact1.php?mailsend");
    }
    

    【讨论】:

      猜你喜欢
      • 2013-07-31
      • 1970-01-01
      • 2018-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-02
      • 2018-04-09
      相关资源
      最近更新 更多