php mail problem with form

Discussion in 'HTML & Website Design' started by imaginexhacked, Aug 11, 2014.

  1. #1
    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!
     
    imaginexhacked, Aug 11, 2014 IP
  2. malky66

    malky66 Acclaimed Member

    Messages:
    3,997
    Likes Received:
    2,248
    Best Answers:
    88
    Trophy Points:
    515
    #2
    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.
     
    malky66, Aug 12, 2014 IP
    ryan_uk likes this.
  3. Aptugo

    Aptugo Greenhorn

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    Sorry malky, but I guess it would be better with "\n"; instead of <br>?

    Cheers!
     
    Aptugo, Aug 13, 2014 IP
  4. Sycrid

    Sycrid Well-Known Member

    Messages:
    130
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #4
    I have second this, as I believe it is the correct answer.
     
    Sycrid, Aug 15, 2014 IP
  5. imaginexhacked

    imaginexhacked Member

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    43
    #5
    Thanks a lot guys ...it worked!
     
    imaginexhacked, Aug 15, 2014 IP
  6. malky66

    malky66 Acclaimed Member

    Messages:
    3,997
    Likes Received:
    2,248
    Best Answers:
    88
    Trophy Points:
    515
    #6
    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!
     
    malky66, Aug 15, 2014 IP
  7. Aptugo

    Aptugo Greenhorn

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #7
    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!
     
    Aptugo, Aug 16, 2014 IP
  8. Nathan Malone

    Nathan Malone Well-Known Member

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    #8
    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.
     
    Nathan Malone, Aug 16, 2014 IP