2012-09-30 174 views
-1

我對PHP沒有太多的經驗 - 我使用了表單生成器來創建此表單。問題在於表單發送數百封空白電子郵件。任何人都可以幫助我解決它嗎?以下是PHP代碼:發送空白郵件的PHP表單

<?php 

$where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/")); 

mail("[email protected]","MESSAGE: website"," 

Someone has submitted a message from your website! Huzzah! 

-------------------------------------------------------------------------------- 

CONTACT INFO: 
" . $_POST['field_1'] . " 
" . $_POST['field_2'] . " 

MESSAGE: 
" . $_POST['field_3'] . " 

-------------------------------------------------------------------------------- 

Also you're a stud. 

"); 

header("Refresh: 0;url=http://www.blah.com/thanks.html"); 

?> 
+0

確保你的HTML表單方法是POST,或者在PHP上使用$ _GET或$ _REQUEST,$ _REQUEST與($ _POST || $ _GET)的值相同, – GTSouza

回答

0

如果你只是確保通過(即實際使用的形式),你會好起來居然有人POST ED數據:

<?php 
    $where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/")); 

     if (!$_POST['field_1'] || !$_POST['field_2'] || !$_POST['field_3']) { 
      header("Location: $where_form_is"); 
      exit; 
     } 

    mail("[email protected]","MESSAGE: website","Someone has submitted a message from your website! Huzzah! 
    CONTACT INFO: 
    " . $_POST['field_1'] . " 
    " . $_POST['field_2'] . " 

    MESSAGE: 
    " . $_POST['field_3'] . " 
    Also you're a stud."); 

    header("Refresh: 0;url=http://www.blah.com/thanks.html"); 
    exit; 
?>