2013-07-24 76 views
1

我正在嘗試爲Wordpress網站創建聯繫表單。僅供參考:客戶希望表單是靜態的,所以他們不需要在將來能夠改變它。我在網上找到了這個表單。我把它放到我的Wordpress自定義頁面中。我也在我的服務器上放了一個mail.php文件。當我點擊提交時,它會將我劫持到我的主頁/主題頁面,並且我的消息永遠不會發送。我不明白爲什麼需要我參加我如何解決這個問題。具有聯繫表格的自定義Wordpress頁面

enter image description here

<table width="400" border="0" align="center" cellpadding="3" cellspacing="1"> 
<tr> 
<td><strong>Contact Form </strong></td> 
</tr> 
</table> 
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1"> 
<tr> 
<td><form name="form1" method="post" action="mail.php"> 
<table width="100%" border="0" cellspacing="1" cellpadding="3"> 
<tr> 
<td width="16%">Subject</td> 
<td width="2%">:</td> 
<td width="82%"><input name="subject" type="text" id="subject" size="50"></td> 
</tr> 
<tr> 
<td>Detail</td> 
<td>:</td> 
<td><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td> 
</tr> 
<tr> 
<td>Name</td> 
<td>:</td> 
<td><input name="name" type="text" id="name" size="50"></td> 
</tr> 
<tr> 
<td>Email</td> 
<td>:</td> 
<td><input name="customer_mail" type="text" id="customer_mail" size="50"></td> 
</tr> 
<tr> 
<td>&nbsp;</td> 
<td>&nbsp;</td> 
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td> 
</tr> 
</table> 
</form> 
</td> 
</tr> 
</table> 

Mail.php

<?php 

// 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]'; 
$mail=mail($to,$subject,$message,$header); 

// Check, if message sent to your email 
// display message "We've recived your information" 
if($mail){ 
echo "We've recived your contact information"; 
} 
else { 
echo "ERROR"; 
} 
?> 
+0

是mail.php在Web根?如果是這樣,請嘗試將表單操作更改爲「/mail.php」。更好的是,使用衆多精彩的聯繫表單插件之一 - 它們將提供更好的用戶反饋,甚至可以使用AJAX。 –

+0

我需要能夠完全自定義超出插件提供的內容,並且/mail.php不起作用 – BDGapps

+0

mail.php在哪裏?你有沒有發佈mail.php的完整內容,因爲你在那裏肯定不會工作 - 它不使用$ _POST的內容。 –

回答

0

這是最簡單的形式,它是開放的,以注射..

$subject ="write something here"; 

// Details 
$message = "write something here"; 

// Mail of sender 
$mail_from = $_POST['customer_mail']; 

// From 
$header="fromfrom: yourname <[email protected]>"; 

// Enter your email address 
$to ='$mail_from'; 

而把其餘代碼後, ..

編輯:

$subject = $_POST['details']; 

// Mail of sender 
$mail_from = $_POST['customer_mail']; 

// From 
$name = $_POST['name']; 

// Details 
$message = 'E-mail sent from: '.$mail_from.'\r\nName: '.$nane.'\r\n'.$_POST['details']; 

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

$mail=mail($to,$subject,$message); 

最後編輯:

<? 

if (isset($_POST['customer_mail'])) { 

    $subject = $_POST['detail']; 

    // Mail of sender 
    $mail_from = $_POST['customer_mail']; 

    // From 
    $name = $_POST['name']; 

    // Details 
    $message = 'E-mail sent from: '.$mail_from.'\r\nName: '.$name.'\r\n'.$_POST['detail']; 

    // Enter your email address 
    $to ='[email protected]'; //edit this 

    $mail=mail($to,$subject,$message); 

    echo "Your mail has been sent"; 

} else { 

?> 

<table width="400" border="0" align="center" cellpadding="3" cellspacing="1"> 
    <tr> 
    <td><strong>Contact Form </strong></td> 
    </tr> 
</table> 

<table width="400" border="0" align="center" cellpadding="0" cellspacing="1"> 
    <tr> 
    <td> 
     <form name="form1" method="post" action="<? echo $_SERVER['PHP_SELF']; ?>"> 

     <table width="100%" border="0" cellspacing="1" cellpadding="3"> 
      <tr> 
      <td width="16%">Subject</td> 
      <td width="2%">:</td> 
      <td width="82%"> 
       <input name="subject" type="text" id="subject" size="50"> 
      </td> 
      </tr> 
      <tr> 
      <td>Detail</td> 
      <td>:</td> 
      <td> 
       <textarea name="detail" cols="50" rows="4" id="detail"></textarea> 
      </td> 
      </tr> 
      <tr> 
      <td>Name</td> 
      <td>:</td> 
      <td> 
       <input name="name" type="text" id="name" size="50"> 
      </td> 
      </tr> 
      <tr> 
      <td>Email</td> 
      <td>:</td> 
      <td> 
       <input name="customer_mail" type="text" id="customer_mail" size="50"> 
      </td> 
      </tr> 
      <tr> 
      <td>&nbsp;</td> 
      <td>&nbsp;</td> 
      <td> 
       <input type="submit" name="Submit" value="Submit"> 
       <input type="reset" name="Submit2" value="Reset"> 
      </td> 
      </tr> 
     </table> 
     </form> 
    </td> 
    </tr> 
</table> 


<? 
} 
?> 
+0

如何使用文本框而不是「在這裏寫東西」; – BDGapps

+0

在''''''' –

+0

之間寫任何東西我需要人們能夠輸入一個表單,並通過不可編輯發送我的意思是客戶端將無法更改它發送到的郵箱 – BDGapps