我在我的网站上使用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 = "someone@domain.com";
$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 :(得分: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";