2017-02-28 195 views
-1

我的PHP表單對我來說工作正常,但不知何故,我收到空白的電子郵件。我試圖直接打開contact.php www.domain.com/php/contact.php,就是這樣。它發送了一封空郵件。有人可以幫我預防嗎?contact.php發送空白電子郵件

PHP

$mailTo = '[email protected]'; 
$mailFrom = $_POST['email']; 
$mailSubject = 'Kontakt'; 
$returnPage = 'versand_erfolgreich.php'; 
$returnErrorPage = 'versand_fehler.php'; 
$mailText = ""; 
if(isset($_POST["submit_button"])) { 

    foreach($_POST as $name => $value) { 

     if(is_array($value)) { 

      $mailText .= $name . ":\n"; 

      foreach($valueArray as $entry) { 

      $mailText .= " " . $value . "\n"; 
      } // ENDE: foreach 
     } // ENDE: if 

     else { 

      $mailText .= $name . ": " . $value . "\n"; 
     } // ENDE: else 
    } // ENDE: foreach 
} // if 

if(get_magic_quotes_gpc()) { 

    $mailtext = stripslashes($mailtext); 
} 

$mailSent = @mail($mailTo, $mailSubject, $mailText, "From: ".$mailFrom); 

if($mailSent == TRUE) { 
    header("Location: " . $returnPage); 
} 
else { 
    header("Location: " . $returnErrorPage); 
} 

exit(); 

HTML

 <form class="form1" id="formular" role="form" action="php/kontakt.php" id="subscribeForm" method="POST"> 


     <input class="inputsolo" type="text" name="Name" id="fname" placeholder="Name*" required="required"> 
     <input class="inputsolo" type="text" name="email" id="email" placeholder="E-Mail Adresse*" required="required"> 
     <input class="inputsolo" type="text" name="Telefon" id="phone" placeholder="0221 111 222*" required="required"> 
     <input class="inputsolo" type="text" name="Betreff" id="betreff" placeholder="Betreff"> 
     <input tabindex="-1" class="inputsolo betreff2" type="text" value="1" name="Betreff2" id="betreff2" placeholder="Betreff"> 
     <input class="inputsolo paket" type="text" name="Ausgewählt:" id="web1" value="Webpaket Basis" readonly><img class="closewahl close1" src="css/images/close.png" alt="close"></img></input> 
     <input class="inputsolo paket" type="text" name="Ausgewählt:" id="web2" value="Webpaket Erweitert" readonly><img class="closewahl close2" src="css/images/close.png" alt="close"></img></input> 
     <input class="inputsolo paket" type="text" name="Ausgewählt:" id="web3" value="Webpaket Business" readonly><img class="closewahl close3" src="css/images/close.png" alt="close"></img></input> 
     <input class="inputsolo paket" type="text" name="Ausgewählt:" id="web4" value="Webpaket Universal" readonly><img class="closewahl close4" src="css/images/close.png" alt="close"></img></input> 
     <textarea class="inputpoly" name="message" placeholder="Ihre Nachricht.." id="message"></textarea> 

     <p id="fehler400"><u>ACHTUNG:<br>Es ist ein Fehler aufgetreten.</u><br><small>Verdacht auf Spam-Bot.</small><br>Bitte kontaktieren Sie uns per E-Mail oder telefonisch.<br><font style="font-family:arial,sans-serif;"><a href="tel:+32221212121" style="text-decoration:none;outline:none;color:#008aff;">+32221212121</a></font></p> 
      <input class="blue-btn" type="submit" id="send" value="Senden"> 
     </form> 
+0

什麼是第5行的$ valueArray?它不應該是'$價值'嗎? – NDFA

回答

0

也許你需要添加name="submit_button"到您的提交按鈕

您發送電子郵件,即使你的$ _POST是空的,所以你shoult把

公告你所有的代碼在if(isset($_POST["submit_button"]))區塊

0

我是不是PHP的人,但我認爲情況應該有如下:

$mailTo = '[email protected]'; 
$mailFrom = $_POST['email']; 
$mailSubject = 'Kontakt'; 
$returnPage = 'versand_erfolgreich.php'; 
$returnErrorPage = 'versand_fehler.php'; 
$mailText = ""; 
if(isset($_POST["submit_button"])) { 

    foreach($_POST as $name => $value) { 

     if(is_array($value)) { 

      $mailText .= $name . ":\n"; 

      foreach($valueArray as $entry) { 

      $mailText .= " " . $value . "\n"; 
      } // ENDE: foreach 
     } // ENDE: if 

     else { 

      $mailText .= $name . ": " . $value . "\n"; 
     } // ENDE: else 
    } // ENDE: foreach 


    if(get_magic_quotes_gpc()) { 

    $mailtext = stripslashes($mailtext); 
} 

$mailSent = @mail($mailTo, $mailSubject, $mailText, "From: ".$mailFrom); 

if($mailSent == TRUE) { 
    header("Location: " . $returnPage); 
} 
else { 
    header("Location: " . $returnErrorPage); 
} 


    } // if 



exit(); 
+0

謝謝!那一個爲我工作:) – GAX

0

你應該包括這裏面的一切,如果

if(isset($_POST["submit_button"])) {

所以不要在一個簡單的訪問發送電子郵件

0

您的代碼應檢查是否有電子郵件的任何值,它不是空白,爲此,你需要做的這個

` 

if(isset($_POST["submit_button"]) && $_POST['email']!='') { 
$mailTo = '[email protected]'; 
$mailFrom = $_POST['email']; 
$mailSubject = 'Kontakt'; 
$returnPage = 'versand_erfolgreich.php'; 
$returnErrorPage = 'versand_fehler.php'; 
$mailText = ""; 
    foreach($_POST as $name => $value) { 
     if(is_array($value)) { 
      $mailText .= $name . ":\n"; 
      foreach($valueArray as $entry) { 
      $mailText .= " " . $value . "\n"; 
      } 
     } 
     else { 
      $mailText .= $name . ": " . $value . "\n"; 
     } 
    } 
}else{ 
    return false; 

} 如果(get_magic_quotes_gpc()){

 $mailtext = stripslashes($mailtext); 
} 
$mailSent = @mail($mailTo, $mailSubject, $mailText, "From: ".$mailFrom); 
if($mailSent == TRUE) { 
    header("Location: " . $returnPage); 
} 
else { 
    header("Location: " . $returnErrorPage); 
} 

exit(); 
` 

試着用這個替換您的。

0

你的代碼看起來粗糙筆記很好,但你的郵件功能被宣告你的後置條件之外,所以當你打開我們的聯繫頁面這是給你的錯誤,當你打開了該頁面(而不提交表格) ,那麼你的數據變量都沒有設置,並通過只是擊中的頁面通常您呼叫的郵件功能,因爲這不是包裹在郵寄支票的條件,簡單的解決方法是

  <?php 
      if(isset($_POST["submit_button"])) { 

       $mailTo = '[email protected]'; 
       $mailFrom = $_POST['email']; 
       $mailSubject = 'Kontakt'; 
       $returnPage = 'versand_erfolgreich.php'; 
       $returnErrorPage = 'versand_fehler.php'; 
       $mailText = ""; 

       foreach($_POST as $name => $value) { 

        if(is_array($value)) { 

         $mailText .= $name . ":\n"; 

         foreach($valueArray as $entry) { 

         $mailText .= " " . $value . "\n"; 
         } // ENDE: foreach 
        } // ENDE: if 

        else { 

         $mailText .= $name . ": " . $value . "\n"; 
        } 
       } 

      if(get_magic_quotes_gpc()) { 

       $mailtext = stripslashes($mailtext); 
      } 

      $mailSent = @mail($mailTo, $mailSubject, $mailText, "From: ".$mailFrom); 

      if($mailSent == TRUE) { 
       header("Location: " . $returnPage); 
      } 
      else { 
       header("Location: " . $returnErrorPage); 
      } 
      } 
      exit(); 
      ?> 

還有,是不是需要聲明這些到後檢查條件以外的變量,因爲你不會需要它們,所以只有在你打算用它們做某事時才設置它們:)

還檢查你缺少你的提交按鈕的名稱屬性(這是非常關鍵),這應該是:

<form class="form1" id="formular" role="form" action="php/kontakt.php" id="subscribeForm" method="POST"> 


    <input class="inputsolo" type="text" name="Name" id="fname" placeholder="Name*" required="required"> 
    <input class="inputsolo" type="text" name="email" id="email" placeholder="E-Mail Adresse*" required="required"> 
    <input class="inputsolo" type="text" name="Telefon" id="phone" placeholder="0221 111 222*" required="required"> 
    <input class="inputsolo" type="text" name="Betreff" id="betreff" placeholder="Betreff"> 
    <input tabindex="-1" class="inputsolo betreff2" type="text" value="1" name="Betreff2" id="betreff2" placeholder="Betreff"> 
    <input class="inputsolo paket" type="text" name="Ausgewählt:" id="web1" value="Webpaket Basis" readonly><img class="closewahl close1" src="css/images/close.png" alt="close"></img></input> 
    <input class="inputsolo paket" type="text" name="Ausgewählt:" id="web2" value="Webpaket Erweitert" readonly><img class="closewahl close2" src="css/images/close.png" alt="close"></img></input> 
    <input class="inputsolo paket" type="text" name="Ausgewählt:" id="web3" value="Webpaket Business" readonly><img class="closewahl close3" src="css/images/close.png" alt="close"></img></input> 
    <input class="inputsolo paket" type="text" name="Ausgewählt:" id="web4" value="Webpaket Universal" readonly><img class="closewahl close4" src="css/images/close.png" alt="close"></img></input> 
    <textarea class="inputpoly" name="message" placeholder="Ihre Nachricht.." id="message"></textarea> 

    <p id="fehler400"><u>ACHTUNG:<br>Es ist ein Fehler aufgetreten.</u><br><small>Verdacht auf Spam-Bot.</small><br>Bitte kontaktieren Sie uns per E-Mail oder telefonisch.<br><font style="font-family:arial,sans-serif;"><a href="tel:+32221212121" style="text-decoration:none;outline:none;color:#008aff;">+32221212121</a></font></p> 
     <input class="blue-btn" type="submit" id="send" value="Senden" name="submit_button"> 
    </form> 

編碼愉快。

+0

感謝您的答案:)我已經改變了你們在這裏建議我的一切,現在它工作正常! :)) – GAX

+0

@GAX很高興知道:) Upvote和馬克正確,如果這有助於你。 :) –

+0

我會upvote,但我不能。我是新的在stackoverflow :) – GAX