2017-04-11 27 views
0

這裏我用了兩個文件contact_us.php & mail.php聯繫我們形成不正常工作使用PHP

其不提供任何錯誤,但沒有得到郵件,請大家幫我任何事情錯在下面的代碼。

contact_us.php

<!DOCTYPE HTML> 
<html> 
<head> 
    <title>TPC</title> 
    <meta name="description" content="website description" /> 
    <meta name="keywords" content="website keywords, website keywords" /> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> 
    <link rel="stylesheet" type="text/css" href="style/style.css" title="style" /> 
</head> 

<body> 
<form action="mail.php" method="post"> 
Name: <input class="contact" type="text" name="your_name" value="" /><br><br> 
Email Address: <input class="contact" type="text" name="your_email" value="" /><br><br> 
Message: <textarea class="contact textarea" rows="8" cols="50" name="your_enquiry"></textarea><br><br> 
<p style="padding-top: 15px"><span>&nbsp;</span><input class="submit" type="submit" name="submit" value="submit" /></p> 
</form> 
</body> 
</html> 

mail.php

<?php 
    if(isset($_POST['submit'], $_POST['name'], $_POST['email'], $_POST['message'], $_POST['recipient'], $_POST['subject'], $_POST['formcontent'], $_POST['mailheader'])) { 
$name = $_POST['name']; 
$email = $_POST['email']; 
$message = $_POST['message']; 
$formcontent="From: $name \n Message: $message"; 
$recipient = "[email protected]"; 
$subject = "Contact Form"; 
$mailheader = "From: $email \r\n"; 

mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); 
    }; 
echo "Thank You!"; 

?> 
+0

打開錯誤報告以找出腳本無法正常工作的原因。 '的error_reporting(E_ALL);' –

+0

感謝@Burhan但我在哪裏可以找到option.canü請解釋更簡單地 –

+1

你的條件是不正確的,因爲'$ _ POST [ 'mailheader']'和'$ _ POST [ 'formcontent' ''不存在。 –

回答

0

沒有與名稱的字段:姓名,電子郵件,消息和不一樣:$ _ POST [ '收件人'],$ _ POST [ '主題'],$ _ POST [ 'formcontent'],$ _ POST [ 'mailheader']

試試下面的代碼或改變形式字段的名稱

 if(isset($_POST['submit'], $_POST['your_name'], $_POST['your_email'], $_POST['your_enquiry'])) { 
    $name = $_POST['your_name']; 
    $email = $_POST['your_email']; 
    $message = $_POST['your_enquiry']; 

/* rest whatever you are trying to do*/ 

} 
+0

謝謝哥們,現在我已經得到了一些這樣想 警告:電子郵件():無法連接到郵件服務器在「localhost」端口25上,在php.ini中驗證您的「SMTP」和「smtp_port」設置,或在第11行的C:\ xampp \ htdocs \ pract \ mail.php中使用ini_set() 錯誤! –

+1

此錯誤是因爲您尚未啓動郵件服務器,請啓動它。它的名字是xampp中的水星。 – programmingArrow

+0

以及配置可以參考這個答案在這裏:http://stackoverflow.com/questions/15965376/how-to-configure-xampp-to-send-mail-from-localhost – programmingArrow