2013-05-07 46 views
0

將數據發送到電子郵件時,我試圖在電子郵件中添加更多變量。在電子郵件中發佈來自PHP表單的數據

<?php 
$to = "[email protected]"; 
$email = $_POST['email']; 
$fname = $_POST['first']; 
$lname = $_POST['last']; 
$account = $_POST['account']; 
$subject = "Safe Haven Reservation"; 
$message = $account; 
$from = $email; 
$headers = "From:" . $from; 
mail($to,$subject,$fname,$lname,$account); 
?> 

我希望能夠添加; $ fname和$ lname添加到郵件中,我無法弄清楚要處理哪些字符。

+3

你不正確地調用「mail」:http://php.net/manual/en/function.mail.php – andrewsi 2013-05-07 15:15:36

回答

0

您應該設置表單方法爲POST像這樣,

<form name="reservations" action="reservations.php" method="post"> 

現在,你將能夠接收郵件!而已!

你的錯誤是你錯誤地設置了表單元素的屬性!您應該使用method="post"而不是method="get"

+0

哇......令人驚訝的是......這種情況經常發生。我應該知道這個......哈哈。下一個問題是...在$信息下,我需要做些什麼來添加它?就像我想添加$ fname或$ lname一樣。 – 2013-05-07 15:31:55

+0

@NathanStotts。您應該更新您的問題並通知我,以便我可以更好地理解您的問題。 – akash4eva 2013-05-07 15:33:41

+0

問題更新 – 2013-05-07 15:39:16

0

變化形式交型getpost

<form name="reservations" action="reservations.php" method="post"> 
0

這些變化,你應該很明顯:(這可能會或可能無法正常工作,手指交叉)

<?php 
    $to = "[email protected]"; 
    $email = $_POST['email']; 

    $fname = $_POST['first']; 
    $lname = $_POST['last']; 

    $account = $_POST['account']; 
    $subject = "Safe Haven Reservation"; 

    $message = $fname." ".$lname."\n".$account; 

    $from = $email; 
    $headers = "From:" . $from; 
    mail($to,$subject,$message); 
?> 
+0

它確實工作,非常感謝!現在到我的下一個冒險編碼 – 2013-05-07 16:15:15

+0

@NathanStotts你可以給我發郵件,只要你有關於編碼的問題,我一定會提供幫助。感謝您的讚賞。 – akash4eva 2013-05-07 16:16:35

相關問題