2013-03-22 55 views
-1

我想要將此表單發送到我的電子郵件地址。除非我使用CAPTCHA,否則PHP郵件表單不工作

這是我使用的PHP(它是位於http://protoolstutorial.org/cottageinn/上的表單)。我需要知道爲什麼這不是通過併發送到我的電子郵件。我從代碼中遺漏了什麼?

<?php 

$your_email ='[email protected]';// <<=== update to your email address 

session_start(); 

$errors = ''; 
$south = ''; 
$east = ''; 
$west = ''; 
$midwest = ''; 
$visitor_email = ''; 

if(isset($_POST['submit'])) 
{ 
    $south = $_POST['south']; 
    $east = $_POST['east']; 
    $west = $_POST['west']; 
    $midwest = $_POST['midwest']; 
    $visitor_email = $_POST['email']; 

    ///------------Do Validations------------- 

    if(empty($visitor_email)) 
    { 
     $errors .= "\n Email is required fields. "; 
    } 

    if(IsInjected($visitor_email)) 
    { 
     $errors .= "\n Bad email value!"; 
    } 

    if(empty($errors)) 
    { 
     //send the email 
     $to = $your_email; 
     $subject="New form submission"; 
     $from = $your_email; 
     $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; 
     $body = "A user submitted the contact form:\n". 
       "South: $south\n". 
       "East: $east\n". 
       "West: $west\n". 
       "Midwest: $midwest\n". 
       "Email: $visitor_email \n". 
       "IP: $ip\n";  
     $headers = "From: $from \r\n"; 
     $headers .= "Reply-To: $visitor_email \r\n"; 

     mail($to, $subject, $body,$headers); 
     header('Location: thank-you.html'); 
    } 
} 

// Function to validate against any email injection attempts 
function IsInjected($str) 
{ 
    $injections = array('(\n+)', 
         '(\r+)', 
         '(\t+)', 
         '(%0A+)', 
         '(%0D+)', 
         '(%08+)', 
         '(%09+)' 
         ); 
    $inject = join('|', $injections); 
    $inject = "/$inject/i"; 
    if(preg_match($inject,$str)) 
    { 
     return true; 
    } 
    else 
    { 
     return false; 
    } 
} 
?> 
+0

你是不是想從本地主機發送?像xampp? – 2013-03-22 14:27:07

+0

爲了幫助你自己,寫下「var_dump($ errors);」之前「如果(空($錯誤))」:) :) – MyMomSaysIamSpecial 2013-03-22 14:28:49

+0

jsut加var_dump不能修復它 – Philip 2013-03-22 14:31:54

回答

0
  1. 在你的php得到錯誤的開頭添加error_reporting(E_ALL)
  2. 在使用它們之前聲明函數。
  3. 對於智能,安全,方便郵件發送,嘗試http://code.google.com/a/apache-extras.org/p/phpmailer/
+0

真的嗎?那根本沒有幫助?這是一個鏈接到一堆下載... – Philip 2013-03-22 14:36:10

+0

在文件的開頭添加error_reporting(E_ALL)後,php是否返回任何錯誤? – ex3v 2013-03-22 14:39:23

+0

不是不是 – Philip 2013-03-22 14:43:34

相關問題