2014-03-07 82 views
0

這是我在HTML5
代碼每當我點擊發送按鈕... phpfiles開放上,我提到任何人可以幫助我,請即郵件ID,而郵件???PHP文件打開時點擊發送

<div class="col-md-6"> 
    <div class="alert alert-success hidden" id="contactSuccess"> 
    <strong>Success!</strong> Your message has been sent to us.</div> 
    <div class="alert alert-danger hidden" id="contactError"> 
    <strong>Error!</strong> There was an error sending your message.</div> 
    <h2 class="short"> 
    <strong>Contact</strong> Us</h2> 
    <form action="php/contact-form.php" id="contactForm" type="post"> 
    <div class="row"> 
     <div class="form-group"> 
     <div class="col-md-6"> 
     <label>Your name *</label> 
     <input type="text" value="" data-msg-required="Please enter your name." maxlength="100" class="form-control" 
     name="name" id="name" /></div> 
     <div class="col-md-6"> 
     <label>Your email address *</label> 
     <input type="email" value="" data-msg-required="Please enter your email address." 
     data-msg-email="Please enter a valid email address." maxlength="100" class="form-control" name="email" 
     id="email" /></div> 
     </div> 
    </div> 
    <div class="row"> 
     <div class="form-group"> 
     <div class="col-md-12"> 
     <label>Subject</label> 
     <input type="text" value="" data-msg-required="Please enter the subject." maxlength="100" class="form-control" 
     name="subject" id="subject" /></div> 
     </div> 
    </div> 
    <div class="row"> 
     <div class="form-group"> 
     <div class="col-md-12"> 
     <label>Message *</label> 
     <textarea maxlength="5000" data-msg-required="Please enter your message." rows="10" class="form-control" name="message" 
     id="message"></textarea></div> 
     </div> 
    </div> 
    <div class="row"> 
     <div class="col-md-12"> 
     <input type="submit" value="Send Message" class="btn btn-primary btn-lg" data-loading-text="Loading..." /> 
     </div> 
    </div> 
    </form> 
</div> 
====================================================== 

和DIS是我的PHP文件代碼...

<?php 
session_cache_limiter('nocache'); 
header('Expires: ' . gmdate('r', 0)); 

header('Content-type: application/json'); 

// Enter your email address below. 
$to = '[email protected]'; 

$subject = $_POST['subject']; 

if($to) { 
    $name = $_POST['name']; 
    $email = $_POST['email']; 

    $fields = array(
     0 => array(
      'text' => 'Name', 
      'val' => $_POST['name'] 
     ), 
     1 => array(
      'text' => 'Email address', 
      'val' => $_POST['email'] 
     ), 
     2 => array(
      'text' => 'Message', 
      'val' => $_POST['message'] 
     ) 
    ); 

    $message = ""; 

    foreach($fields as $field) { 
     $message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br>\n"; 
    } 

    $headers = ''; 
    $headers .= 'From: ' . $name . ' <' . $email . '>' . "\r\n"; 
    $headers .= "Reply-To: " . $email . "\r\n"; 
    $headers .= "MIME-Version: 1.0\r\n"; 
    $headers .= "Content-Type: text/html; charset=UTF-8\r\n"; 

    if (mail($to, $subject, $message, $headers)){ 
     $arrResult = array ('response'=>'success'); 
    } else{ 
     $arrResult = array ('response'=>'error'); 
    } 

    echo json_encode($arrResult); 

} else { 

    $arrResult = array ('response'=>'error'); 
    echo json_encode($arrResult); 

} 
?> 

每當我點擊發送按鈕... phpfiles開放的,而郵件對郵件ID有人可以幫我請?

+0

你在哪裏運行這段代碼? PHP安裝/啓用並正常運行? – djot

+0

@djot:是對的。請檢查PHP是否安裝。 – skparwal

+0

是的PHP安裝我運行此代碼THRUGH WAMP服務器 – user3391892

回答

0

更改下面的代碼

<form action="php/contact-form.php" id="contactForm" type="post"> 

<form action="php/contact-form.php" id="contactForm" method="post"> 
+0

代碼從某處複製...所以'方法'應該是默認的,如果失蹤...和工作。 – djot

+0

我購買了該協議表格中的模板是否有其不工作 – user3391892

0

您必須安裝本地主機服務器像XAMPP或wampp。 然後將文件放入
對於Xampp:htdocx/將文件放入htdocx文件夾並運行。
敵人wampp:www/把你的文件放入www文件夾並運行。

+0

先生我做了這個使用xampp – user3391892

+0

打開xampp控制pannel並檢查Apache和MySql服務器是否正在運行? 頁面提交時仍顯示PHP代碼? –

0

將您的type =「post」轉換爲method =「post」。另外,您需要將您的項目放入WAMP目錄的htdocs文件夾中,並確保WAMP服務器已打開。

您應該首先嚐試一個「Hello World」測試,以確保一切正常運行。查看Web上的教程。

+0

將您的type =「post」轉換爲method =「post」。仍然與它相同 – user3391892

+0

您的項目是否在WAMP目錄內的htdocs文件夾中? WAMP絕對開啓了嗎? – CheckeredMichael

+0

先生我做了這個使用xampp offcourse是先生.... 並將所有文件放在相同的Xampp:htdocx /文件夾... – user3391892