2017-05-25 30 views
-1

PHP表單郵件進入到一個空白頁:http://www.commercialinsulation.com/proto/html/php/mail_form.phpPHP的聯繫郵件進入到一個空白頁

我是新來這個的不知道爲什麼會這樣。我將它上傳到服務器。我查看了所有可能的信息。請幫忙!應該是所有令人敬畏的編碼者的簡單事情。

<?php 

error_reporting(E_ALL); 
ini_set('display_errors', 1); 

ini_set('display_errors', 'On'); 
ini_set('html_errors', 0); 
error_reporting(-1); 


// This work is licensed under the MIT License - http://www.opensource.org/licenses/mit-license.php 


// OPTIONS - PLEASE CONFIGURE THESE BEFORE USE! 

    $yourEmail = "[email protected]"; // the email address you wish to receive these mails through 
    $yourWebsite = "http://www.test.com"; // the name of your website 
    $thanksPage = ''; // URL to 'thanks for sending mail' page; leave empty to keep message on the same page 
    $maxPoints = 4; // max points a person can hit before it refuses to submit - recommend 4 


// --- DO NOT EDIT BELOW HERE ----------------------- 

$error_msg = null; 
$result = null; 

function isBot() { 
    $bots = array("Indy", "Blaiz", "Java", "libwww-perl", "Python", "OutfoxBot", "User-Agent", "PycURL", "AlphaServer", "T8Abot", "Syntryx", "WinHttp", "WebBandit", "nicebot"); 

    $isBot = false; 
    foreach ($bots as $bot) 
    if (strpos($_SERVER['HTTP_USER_AGENT'], $bot) !== false) 
     $isBot = true; 

    if (empty($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == " ") 
     $isBot = true; 

    exit("Bots not allowed.</p>"); 
} 

if ($_SERVER['REQUEST_METHOD'] == "POST") { 
    function clean($data) { 
     $data = trim(stripslashes(strip_tags($data))); 
     return $data; 
    } 

    $points = (int)0; 

    $badwords = array("adult", "beastial", "bestial", "blowjob", "clit", "cum", "cunilingus", "cunillingus", "cunnilingus", "cunt", "ejaculate", "fag", "felatio", "fellatio", "fuck", "fuk", "fuks", "gangbang", "gangbanged", "gangbangs", "hotsex", "hardcode", "jism", "jiz", "orgasim", "orgasims", "orgasm", "orgasms", "phonesex", "phuk", "phuq", "porn", "pussies", "pussy", "spunk", "xxx", "viagra", "phentermine", "tramadol", "adipex", "advai", "alprazolam", "ambien", "ambian", "amoxicillin", "antivert", "blackjack", "backgammon", "texas", "holdem", "poker", "carisoprodol", "ciara", "ciprofloxacin", "debt", "dating", "porn", "link=", "voyeur"); 
    $exploits = array("content-type", "bcc:", "cc:", "document.cookie", "onclick", "onload", "javascript"); 

    foreach ($badwords as $word) 
     if (strpos($_POST['comments'], $word) !== false) 
      $points += 2; 

    foreach ($exploits as $exploit) 
     if (strpos($_POST['comments'], $exploit) !== false) 
      $points += 2; 

    if (strpos($_POST['comments'], "http://") !== false || strpos($_POST['comments'], "www.") !== false) 
     $points += 2; 
    if (isset($_POST['nojs'])) 
     $points += 1; 
    if (preg_match("/(<.*>)/i", $_POST['comments'])) 
     $points += 2; 
    if (strlen($_POST['name']) < 3) 
     $points += 1; 
    if (strlen($_POST['comments']) < 15 || strlen($_POST['comments'] > 1500)) 
     $points += 2; 

    foreach ($_POST as $key => $value) 
     $_POST[$key] = trim($value); 

    if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['comments'])) { 
     $error_msg .= "Name, e-mail and comments are required fields. \n"; 
    } elseif (strlen($_POST['name']) > 15) { 
     $error_msg .= "The name field is limited at 15 characters. Your first name or nickname will do! \n"; 
    } elseif (!preg_match("/^[a-zA-Z-'\s]*$/", stripslashes($_POST['name']))) { 
     $error_msg .= "The name field must not contain special characters. \n"; 
    } elseif (!preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', strtolower($_POST['email']))) { 
     $error_msg .= "That is not a valid e-mail address. \n"; 
    } elseif (!empty($_POST['url']) && !preg_match('/^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i', $_POST['url'])) 
     $error_msg .= "Invalid website url."; 

    if ($error_msg == NULL && $points <= $maxPoints) { 
     $subject = "Automatic Form Email"; 

     $message = "You received this e-mail message through your website: \n\n"; 
     foreach ($_POST as $key => $val) { 
      $message .= ucwords($key) . ": " . clean($val) . "\r\n"; 
     } 
     $message .= 'IP: '.$_SERVER['REMOTE_ADDR']."\r\n"; 
     $message .= 'Browser: '.$_SERVER['HTTP_USER_AGENT']."\r\n"; 
     $message .= 'Points: '.$points; 

     if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) { 
      $headers = "From: $yourEmail \r\n"; 
      $headers .= "Reply-To: {$_POST['email']}"; 
     } else { 
      $headers = "From: $yourWebsite <$yourEmail> \r\n"; 
      $headers .= "Reply-To: {$_POST['email']}"; 
     } 

     if (mail($yourEmail,$subject,$message,$headers)) { 
      if (!empty($thanksPage)) { 
       header("Location: $thanksPage"); 
       exit; 
      } else { 
       $result = 'Your mail was successfully sent.'; 
      } 
     } else { 
      $error_msg = 'Your mail could not be sent this time.'; 
     } 
    } else { 
     if (empty($error_msg)) 
      $error_msg = 'Your mail looks too much like spam, and could not be sent this time. ['.$points.']'; 
    } 
} 
function get_data($var) { 
    if (isset($_POST[$var])) 
     echo htmlspecialchars($_POST[$var]); 
} 
?> 

HTML:

<form class="required-form" action="php/mail_form.php" method="post"> 
    <ol class="forms"> 
     <li> 
      <label for="name">Name</label> 
      <input type="text" name="name" id="name" /> 
     </li> 
     <li> 
     <label for="email"><em class="required">*</em> Your Email</label> 
     <input type="text" name="email" id="email" class="required" /> 
    </li> 

    <li><label for="message">Message</label> 
     <textarea name="message" id="message"></textarea></li> 
     <li class="buttons submit"> 
     <button type="submit">Send Message</button></li> 
    </ol> 
</form> 
+0

您是否在瀏覽器控制檯或服務器控制檯上收到任何錯誤? –

+0

盡我所知,'$ thanksPage'沒有任何價值,也沒有看到你使用'get_data()'方法的地方,也沒有看到'$ error_msg'被回顯的地方。 –

+0

我沒有收到任何錯誤消息,它停止尋找http://www.commercialinsulation.com/proto/html/php/mail_form.php。 – LisaG

回答

1

您已經爲您的形式對特定文件的操作,而你想留在同一頁上。

像這樣調整你的代碼,這樣頁面就會在提交時重新加載,然後執行它的魔法。

<form class="required-form" action="" method="post"> 
+0

或者您可以將其更改爲「/proto/html/php/mail_form.php」。它也是空白的,因爲您在點擊URL時沒有POST。這是一個GET,你不能在PHP文件中處理。 – Ally

+0

@RST ,,謝謝你的回覆。如果我將操作更改爲

,它將返回contact.html(謝謝!),但沒有謝謝您提交的提示消息。如果我使用「/proto/html/php/mail_form.php」,它仍然掛起。無論如何,我還沒有收到測試郵件。 – LisaG

+0

這應該是這麼簡單......然而,我已經花了三天時間在這個......啊! – LisaG