likedvm Posted September 1, 2014 Share Posted September 1, 2014 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> Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted September 1, 2014 Share Posted September 1, 2014 (edited) 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 $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 September 1, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted September 1, 2014 Share Posted September 1, 2014 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.