2014-09-01 122 views
-1

我正在爲我的網站使用PHP表格&我無法正確發送電子郵件,它發給我的只是名字和姓氏,但沒有其他的郵箱,任何幫助?另外我該如何保護它?PHP電子郵件表格無法正常工作

這是PHP文件:

<!DOCTYPE html> 
<html> 
<body> 
<?php 
$fname = $_POST['fname']; 
$lname = $_POST['lname']; 
$email = $_POST['email']; 
$paddress = $_POST['paddress']; 
$cnumber = $_POST['cnumber']; 
$bedrooms = $_POST['bedrooms']; 
$furnished = $_POST['furnished']; 
$unfurnished = $_POST['unfurnished']; 
$partfurnished = $_POST['partfurnished']; 
$townwork = $_POST['townwork']; 
$distancework = $_POST['distancework']; 
$when = $_POST['when']; 
$maximum = $_POST['maximum']; 
$additional = $_POST['additional']; 

//Sending Email to form owner 
$header = "From: $email\n" 
. "Reply-To: $email\n"; 
$subject = "Property locator"; 
$email_to = "[email protected]"; 
$message = "Name: $fname . $lname\n"; 
"Email: $email\n"; 
"Postal Address: $paddress\n"; 
"Contact Number: $cnumber\n"; 
"Number of Bedrooms: $bedrooms\n"; 
"Furnished, Unfurnished or Part Furnished: $furnished . $unfurnished . $partfurnished\n"; 
"Which town will you be working in?: $townwork\n"; 
"Preferred distance from property to work (miles): $distancework\n"; 
"When do you need the accomodation?: $when\n"; 
"Maximum rental per month(£): $maximum\n"; 
"Additional information: $additional\n"; 
mail($email_to, $subject ,$message ,$header) ; 

?> 
<h1>Thank You for Your Submission</h1> 
<p><a href="http://www.">Click here to go back</a></p> 
</body> 
</html> 
+0

請看頭注入預防。 – PeeHaa 2014-09-01 19:29:40

+0

'';''結束字符串,您應該使用'「。」'來連接 – kero 2014-09-01 19:29:44

+0

@Dom對不起,如此生硬,但你應該學習PHP – kero 2014-09-01 20:07:51

回答

1

注意分號這行的末尾:

$message = "Name: $fname . $lname\n"; 

它結束的語句,所以它後面的線不連接起來以$message

這可以解決你的問題:

$message = "Name: $fname . $lname\n" . 
    "Email: $email\n" . 
    "Postal Address: $paddress\n" . 
    "Contact Number: $cnumber\n" . 
    "Number of Bedrooms: $bedrooms\n" . 
    "Furnished, Unfurnished or Part Furnished: $furnished . $unfurnished . $partfurnished\n" . 
    "Which town will you be working in?: $townwork\n" . 
    "Preferred distance from property to work (miles): $distancework\n" . 
    "When do you need the accomodation?: $when\n" . 
    "Maximum rental per month(£): $maximum\n" . 
    "Additional information: $additional\n";