2014-03-01 18 views
2

我的代碼是這樣的:PHP電子郵件的形式,使其本地

<?php 
if(isset($_POST['submit'])){ 
$to = "[email protected]"; // this is your Email address 
$from = $_POST['email']; // this is the sender's Email address 
$first_name = $_POST['first_name']; 
$last_name = $_POST['last_name']; 
$subject = "Form submission"; 
$subject2 = "Copy of your form submission"; 
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message']; 
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message']; 

$headers = "From:" . $from; 
$headers2 = "From:" . $to; 
mail($to,$subject,$message,$headers); 
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender 
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly."; 
// You can also use header('Location: thank_you.php'); to redirect to another page. 
} 
?> 

<!DOCTYPE html> 
<head> 
<title>Form submission</title> 
</head> 
<body> 

<form action="" method="post"> 
First Name: <input type="text" name="first_name"><br> 
Last Name: <input type="text" name="last_name"><br> 
Email: <input type="text" name="email"><br> 
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br> 
<input type="submit" name="submit" value="Submit"> 
</form> 

</body> 
</html> 

我得到它關閉的一個PHP電子郵件的形式另外一個問題,我想在本地測試。我該怎麼做呢?

我最終打算在我正在爲朋友工作的網站上發佈它。

+1

你的意思是...你如何建立一個Web服務器,將服務於PHP頁面? – Mike

+0

@Mike,Err,我不知道。這是必要的嗎?我不知道PHP如何工作 – JoeJoe2416

+3

如果你不知道PHP是如何工作的,那麼你確實需要做一些研究。您需要安裝和配置計算機上的Web服務器(例如Apache),郵件服務器和PHP以對其進行測試。看看http://stackoverflow.com/questions/2034501/how-does-php-work和谷歌是你的朋友沒有覆蓋那裏的任何其他。 – Mike

回答