2014-03-28 62 views
-2

我創建一個表單來發送聯繫人數據。我希望客戶發送表單並保留在主頁面(index.html)中。這裏的PHP代碼:發送表單並保留在頁面

PHP:

if(mail($to, $subject, $message, $headers)) 
    echo"<script>alert('message send succesfully')</script>"; 
else 
    echo"<script>alert('message not send')</script>"; 
+0

使用谷歌和做一些努力https://www.google.com /search?site=webhp&source=hp&q=contact+form+with+ajax+and+php&oq=contact+form+with+aja&gs_l=hp.3.1.0l3j0i22i30l7.1345265.1349238.0.1350971.29.27.2.0.0.0.1068.4877.13j7j4j6-1j1 .26.0 .... 0 ... 1c.1.38.hp..11.18.1334.0.9vl_3sjCrDs –

+0

Simpl e答案:以「action」形式放置相同的頁面。高級:使用AJAX。 – aurbano

+0

無關信息。 – Arun

回答

0

更改到index.php

添加此

// 'to' should be the name of your input field 
if (!empty($_POST['to'])) { 
    if (mail($to, $subject, $message, $headers)) { 
     echo"<script>alert('message send succesfully');</script>"; 
    } 
    else { 
     echo"<script>alert('message not send');</script>"; 
    } 
} 
+0

抱歉,但無法正常工作。我也不能把相同的頁面放在該動作中,因爲那樣它就不能識別php(contact.php) –

+0

請添加您的完整html代碼。我更新了js代碼並添加了; – neonoxGER