2013-05-14 42 views
-4

我的聯繫表格的HTML頁面再下面的HTML代碼是PHP代碼聯繫郵件錯誤

<form name="form1" method="post" action="contact.php" id="contactform"> 
           <table width="100%" border="0" cellspacing="1" cellpadding="3"> 
            <tr> 
             <td><input name="name" type="text" id="name" ONFOCUS="clearDefault(this)" value="Name" size="90" style="background: #DAEDFF; border:1px solid #DAEDFF; border-radius:3px; height: 25px;"></td> 
            </tr> 
            <tr> 
             <td><input name="customer_mail" type="text" value="Email" ONFOCUS="clearDefault(this)" id="customer_mail" size="90" style="background: #DAEDFF; border:1px solid #DAEDFF; border-radius:3px; height: 25px;"></td> 
            </tr> 
            <tr> 
             <td width="82%"><input name="subject" type="text" value="Subject" ONFOCUS="clearDefault(this)" id="subject" size="90" style="background: #DAEDFF; border:1px solid #DAEDFF; border-radius:3px; height: 25px;"></td> 
            </tr> 
            <tr> 
             <td><textarea name="detail" cols="90" rows="8" id="detail" style="background: #DAEDFF; border:1px solid #DAEDFF; border-radius:3px;"></textarea></td> 
            </tr> 
            <tr> 
             <td style="padding-left: 530px;"><input type="submit" name="Submit" value="Send" style="background: #1B99E8; border: 1px solid #1B99E8; color: #ffffff; border-radius:3px;"></td> 
            </tr> 
          </table> 
         </form> 

contact.php文件

<?php 

$subject  = $_POST['subject']; 
$detail   = $_POST['detail']; 
$customer_mail = $_POST['customer_mail']; 
$name   = $_POST['name']; 

// Contact subject 
$subject ="$subject"; 

// Details 
$message="$detail"; 

// Mail of sender 
$mail_from="$customer_mail"; 

// From 
$header="from: $name <$mail_from>"; 

// Enter your email address 
$to ='[email protected]'; 
$send_contact=mail($to,$subject,$message,$header); 

// Check, if message sent to your email 
// display message "We've recived your information" 
if($send_contact){ 
echo '<script language="javascript">confirm("We have received your request, our team will contact you shortly.")</script>'; 
echo '<script language="javascript">window.location = "contact.html"</script>'; 
} 
else { 
echo '<script language="javascript">confirm("Oops Sorry for the inconvinience.")</script>'; 
echo '<script language="javascript">window.location = "contact.html"</script>'; 
} 
?> 

以上是我的代碼plz幫助我克服我的問題,因爲我在網站託管,它適用於我的本地服務器,但不工作在網站

+2

我們無法閱讀您的想法,請發佈您的代碼。 – kennypu 2013-05-14 09:29:17

+0

沒有人可以幫助看到生成錯誤的代碼 – 2013-05-14 09:29:56

+0

確保sendmail在您的主機上工作。 – ChamingaD 2013-05-14 10:02:02

回答

0

我想你的代碼有問題window.location =「contact.html」部分。 如果你想重定向到這個頁面,請嘗試給絕對路徑。 您也可以嘗試window.location.hrefwindow.open。 請注意,window.open將在新窗口中打開。

+0

如果點擊「發送」時沒有連接到你的php文件,他們請確保contact.php實際上存在於同一個文件夾中。 – 2013-05-14 10:58:23

+0

s我在文件夾中保留了dat contact.php文件,但之後也沒有發生同樣的問題'系統找不到指定的路徑'。 – Developer 2013-05-14 11:09:33

+0

點擊發送時,它會重定向到contact.php頁面,但顯示爲「系統找不到指定的路徑」。 – Developer 2013-05-14 11:11:01

0

你也有一個很常見的錯誤,很多人有「聯繫我們」表單。

// Mail of sender 
$mail_from="$customer_mail"; 

這將打破SPF和也導致DMARC失敗,你將永遠不會從一些人得到的消息,如果你的郵件服務器使用上有啓用DMARC。

由於DMARC是一個較新的協議,很多舊的cookie切割器代碼聯繫我們形式 - 並沒有考慮到這一點。

你可以閱讀更多有關在這裏:"DMARC - Contact Form Nightmare"

的建議的解決方法將是這樣做:

$mail_from='[email protected]'; 
$subject ="$subject" . $_POST['customer_mail']; 

這樣 - 你避免在文章中的問題提綱。您無法快速點擊「回覆」按鈕,但至少您會收到啓用了DMARC的客戶發送的電子郵件。