Hello, I have coded a simple html form with a php script to collect and email the results of the form to me. My form html is: <form action="/landingpages/getoutofdebt/form.php" method="post" name="getoutofdebt" id="getoutofdebt"> <p>Name: <input name="name" type="text" id="name" /> </p> <p>Phone: <input name="phone" type="text" id="phone" /> </p> <p>Email: <input name="email" type="text" id="email" /> </p> <p>City: <input name="city" type="text" id="city" /> </p> <p>Province: <input name="province" type="text" id="province" /> </p> <p>Take Home Pay: <input name="pay" type="text" id="pay" /> </p> <p>Assets: <input name="assets" type="text" id="assets" /> </p> <p> <label for="debts">Debts:</label> <textarea name="debts" id="debts">Please add Amount and Description </textarea> <br /> </p> <p> <input type="submit" name="submit" id="submit" value="Submit to Trustee" /> <p> </form> While my php script is: <?php $name = $_POST ['name']; $phone = $_POST ['phone']; $email= $_POST ['email']; $city= $_POST ['city']; $province= $_POST ['province']; $pay= $_POST ['pay']; $assets= $_POST ['assets']; $debts= $_POST ['debts']; $to = ''; $subject = 'Subject 2'; mail ($to, $subject, $message, "From: ". $name); echo "Thank You! Your Message Has Been Received."; ?> I receive an email with the Subject 2 subject line to my email and the form goes to the echo page with the "thank you" message after the form fields are filled in and the submit button is pressed. The issue is the email is blank with none of the test information I filled out in the form and so the form results are not captured. Did I code something wrong with the $_POST? I am at a loss as I know no php and would greatly appreciate a steer in the right direction. Thanks and cheers!
You aren't defining the $message variable, try inserting this $message = 'Name: '.$name.'<br> Phone: '.$phone.'<br> Email: '.$email.'<br> City: '.$city.'<br> Province: '.$province.'<br> Pay: '.$pay.'<br> Assets: '.$assets.'<br> Debts: '.$debts.'<br>'; Code (markup): after the following code: $name = $_POST ['name']; $phone = $_POST ['phone']; $email= $_POST ['email']; $city= $_POST ['city']; $province= $_POST ['province']; $pay= $_POST ['pay']; $assets= $_POST ['assets']; $debts= $_POST ['debts']; Code (markup): You also need to use some sort of validation and security if using that on a live site.
Well if you want to be pedantic..then yes, the point of my post was to show him why the message variable wasn't being sent. Cheers!
No, at all, sorry, I can assure you I didn't want to be a smug. Your answer is correct, I just added my two cents! Have a nice day!
To add to the solution that has already been posted, you might want to consider escaping the user-inputted data for security reasons as well.