php联系表单不发送内容

时间:2014-01-03 19:48:06

标签: php forms form-submit

我的网站上有几个php表单,他们在提交表单时都会通过电子邮件发送表单的内容。直到两周前我没有遇到任何问题,但突然间我才开始收到空的电子邮件(只有标签而不是用户信息)我试图解决这个问题,但没有运气。请帮帮我。

我的表格:

<form id="form1" name="form1" method="post" action="../iletisimform.php">
 <p><span class="sss_cevap">İletişim Formu</span></p>
  <table width="100%" border="0" cellpadding="6">
   <tr>
   <td width="20%" align="right" bgcolor="#EFF5F8"><label for="ad">Ad: </label></td>
   <td width="80%" align="left" bgcolor="#EFF5F8"><input name="ad" type="text" id="ad" size="35" maxlength="50" /> 
   *</td>
   </tr>
        <tr>
          <td align="right" bgcolor="#EFF5F8"><label for="soyad">Soyad:</label></td>
          <td align="left" bgcolor="#EFF5F8"><input name="soyad" type="text" id="soyad" size="35" maxlength="50" /> 
          *</td>
        </tr>
        <tr>
          <td align="right" bgcolor="#EFF5F8"><label for="firma">Firma:</label></td>
          <td align="left" bgcolor="#EFF5F8"><input name="firma" type="text" id="firma" size="35" maxlength="70" /> 
          *</td>
        </tr>
        <tr>
          <td align="right" bgcolor="#EFF5F8"><label for="telefon">Telefon:</label></td>
          <td align="left" bgcolor="#EFF5F8"><input name="telefon" type="text" id="telefon" size="35" maxlength="12" /> 
          *</td>
        </tr>
        <tr>
          <td align="right" bgcolor="#EFF5F8"><label for="email">Email:</label></td>
          <td align="left" bgcolor="#EFF5F8"><input name="email" type="text" id="email" size="35" maxlength="70" /> 
          *</td>
        </tr>
        <tr>
          <td align="right" bgcolor="#EFF5F8"><label for="mesaj">Mesaj:</label></td>
          <td align="left" bgcolor="#EFF5F8"><textarea name="mesaj" id="mesaj" cols="35" rows="5"></textarea> 
          *</td>
        </tr>
        <tr>
          <td align="right" bgcolor="#EFF5F8">&nbsp;</td>
          <td align="left" bgcolor="#EFF5F8"><input name="promosyon" type="checkbox" id="promosyon" value="promogonder" />
          <label for="promosyon">Insuladd promosyonlarından haberdar olmak istiyorum...</label></td>
        </tr>
        <tr>
          <td align="right" bgcolor="#EFF5F8"><label for="Temizle"></label>
            <label for="temizle"></label>
          <input type="reset" name="temizle" id="temizle" value="Temizle" /></td>
          <td align="left" bgcolor="#EFF5F8"><label for="gönder"></label>
          <input type="submit" name="gönder" id="gönder" value="Gönder" /></td>
        </tr>
      </table>
          <p>* Alanları gereklidir<br />
    </p>
    </form> 

我的剧本:

<?php


/* Subject and Email Variables */

    $emailSubject = 'Insuladd Bilgi Talebi!';
    $webMaster = 'info@insuladd.com.tr';

/* Gathering Data Variables */

    $nameField = $_POST['ad'];
    $lastnameField = $_POST['soyad'];
    $companyField = $_POST['firma'];
    $telephoneField = $_POST['telefon'];
    $emailField = $_POST['email'];
    $messageField = $_POST['mesaj'];
    $promotionField = $_POST['promosyon'];

    $body = <<<EOD
<br><hr><br>
Name: $ad <br>
Last Name: $soyad <br>
Company: $firma <br>
Telephone: $telefon <br>
Email: $email <br>
Message: $mesaj <br>
Promotion: $promosyon <br>
EOD;

    $headers = "From: $email\r\n";
    $headers .= "Content-type: text/html\r\n";
    $success = mail($webMaster, $emailSubject, $body, $headers);

/* Results rendered as HTML */

    $theResults = <<<EOD

EOD;
echo header ("Location: http://www.insuladd.com.tr/iletisim/tesekkurler.html");

?>

1 个答案:

答案 0 :(得分:1)

我看不到任何功能上的错误会阻止您接收表单的内容。我可以得出的唯一结论是,您很可能会收到内容空白的人提交的内容。很可能它来自机器人。

通过验证用户输入以确保它不为空,可以很容易地防止这种情况。沿着那条线做某事的方法可能是......

<?php
    if ( empty($_POST['ad']) || empty($_POST['soyad']) || empty($_POST['firma']) || empty($_POST['telefon']) || empty($_POST['email']) || empty($_POST['mesaj']) || empty($_POST['promosyon']) )
    {
        header('Location: [Replace with url to page with error message]');
    }

/* Subject and Email Variables */

    $emailSubject = 'Insuladd Bilgi Talebi!';
    $webMaster = 'info@insuladd.com.tr';

/* Gathering Data Variables */

    $nameField = $_POST['ad'];
    $lastnameField = $_POST['soyad'];
    $companyField = $_POST['firma'];
    $telephoneField = $_POST['telefon'];
    $emailField = $_POST['email'];
    $messageField = $_POST['mesaj'];
    $promotionField = $_POST['promosyon'];

    $body = <<<EOD
<br><hr><br>
Name: $nameField <br>
Last Name: $lastnameField <br>
Company: $companyField <br>
Telephone: $telephoneField <br>
Email: $emailField <br>
Message: $messageField <br>
Promotion: $promotionField <br>
EOD;

    $headers = "From: $email\r\n";
    $headers .= "Content-type: text/html\r\n";
    $success = mail($webMaster, $emailSubject, $body, $headers);

/* Results rendered as HTML */

    $theResults = <<<EOD

EOD;
header ("Location: http://www.insuladd.com.tr/iletisim/tesekkurler.html");

?>

有更优雅的方法来防止问题并实施最基本的验证,但这可以让您了解应该尝试的内容。