2012-01-13 88 views
0

好的我有我們的聯繫表完全正常工作,並正確處理。我有兩個問題...聯繫表格php幫助

  1. 的聯繫表格頁面上,我想補充一個複選框,供用戶勾選以藏漢發送電子郵件的副本給他們。

  2. 關於進程形式的一部分我想重定向到錯誤頁面,如果一切都可怕的錯誤。

目前我的形式提交,我有行動要thankyou.php

我的形式處理我有thankyou.php頁面內添加,但如果需要的話可以單獨拉出來。

.......................................

我的表單處理低於(很簡單)

<?php 

$youremail = "[email protected]"; 

$yourname = $_POST['yourname']; 
$email = $_POST['email']; 
$location = $_POST['location']; 
$textarea = $_POST['textarea']; 

$headers = "From: $email"; 

$content = "Hello there! This is a message from your contact form.\r\n 
\r\n 
\r\n 
Name: $yourname\r\n 
\r\n 
E-mail: $email\r\n 
\r\n 
Location: $location\r\n 
\r\n 
Message: $textarea\r\n\r\n"; 

$send = mail($youremail, 'Message from your conatct form', $content, $headers); 

if($send) 
{ 
echo "ok"; 
} 

我不是布里爾用PHP所以任何幫助讚賞

回答

1
<?php 
$youremail = "[email protected]"; 
$yourname = $_POST['yourname']; 
$email  = $_POST['email']; 
$location = $_POST['location']; 
$textarea = $_POST['textarea']; 
$ReceiveMail= $_POST['txtReceive']; 

if($ReceiveMail == "yes") { 
    $content = ""; 
    $headers = "From: $email"; 
    @mail($email, 'Mail Notification', $content, $headers); 
} 
    $headers = "From: $email"; 
    $content = "Hello there! This is a message from your contact form.\r\n 
    \r\n 
    \r\n 
    Name: $yourname\r\n 
    \r\n 
    E-mail: $email\r\n 
    \r\n 
    Location: $location\r\n 
    \r\n 
    Message: $textarea\r\n\r\n"; 
    $send = mail($youremail, 'Message from your conatct form', $content, $headers); 
    if($send) { 
     header("location:thankyou.php"); 
     exit; 
    } 
    else { 
     header("location:error.php"); 
     exit; 
    } 
?> 

我在窗體中添加了一個複選框,並檢查服務器端的值。 試試這個。希望它會幫助

+0

謝謝穆圖:)會給它一個去 – 422 2012-01-13 05:07:23

1

如果你想發送郵件的副本,那麼您需要添加適當的標題的郵件,如:

 

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
$headers .= 'To: Somename <[email protected]>' . "\r\n"; 
$headers .= 'Cc: '.$yourCopyMail . "\r\n"; // this is for copy 
//then 
if(mail(....)) { 
    echo "sent"; 
} 
else { 
    header("Location: url_to_your_error_page"); 
    exit; 
} 
 
+0

謝謝Sudhir,我在看別人轉到,......無法弄清楚。將給那一個旋轉謝謝你 – 422 2012-01-13 05:08:08

1

關於你的第一個問題:

This page給出了一個關於如何添加複選框到你的表單並接收下一頁的值的快速教程。在處理表單提交時,只需查看變量$_POST["checkboxname"]並查看它是否設置爲您賦予該複選框的值(或者它是否設置爲真)。如果是,則只需重複該命令發送電子郵件,並將用戶的電子郵件作爲收件人。

在你的情況下,它看起來像這將是$send = mail($email, 'Message from your conatct form', $content, $headers);

我不知道該怎麼回答你的第二個問題,因爲「如果一切順利可怕的錯誤」是不是一個特別有意義的條件。