Jump to content

PHP form not working correctly


likedvm

Recommended Posts

Hey guys, I'm using a PHP form for my website & I can't get it to send the email correctly, all it send me is the first and last name, but none of the other boxes, any help? Also how can I secure it?

 

This is the PHP file:

 

<!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>
Link to comment
Share on other sites

Because you have not added the other fields to the email body. The email body is defined by the $message variable

 

Here you start to define the email body on the first line. But the other lines you define a bunch of strings but you haven't told PHP what to do with them  :tease-01:

$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";

You need to prepend the rest of the lines with  $message .=  so they are added to email body. 

 

OR change the semi-colons at end of all the lines expect the very last line one to a period 

Edited by Ch0cu3r
Link to comment
Share on other sites

Sometimes it's a good idea to actually read the code before you hand out “advice”.

 

This script essentially turns the server into an open mail relay: Anybody can send any mail to any address (by injecting their own headers). If the spam mafia finds this, the server IP will be blacklisted in no time, and I'm sure your web hoster won't find that very funny.

 

Do not use the mail() function. This is a low-level function for experts who need to manually assemble the raw message and know exactly what they're doing. It is not for simply sending out an e-mail. If that's your goal, you need a mailer library like PHPMailer

 

You also can't just drop any user input into the e-mail body. You need to escape the values first. Otherwise, people will use this to inject all kinds of nasty JavaScript code.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.