treehouse : what would you like to learn today?
Web Design Web Development iOS Development

ISSUE! Form Not collecting information???

  • Hello,
    I am working on a site which is in a different language, and have added a form to a page called request when clicked submit it is processed by a page called contact.php and so when the user has clicked submit they should be redirected to a page called thankyou.html letting them know that their message is sent, i have edited the php form so when i click submit the form is sent and i am redirected to the thankyou.html viewing my message is ent however the php is not collecting all the information from the request page because when i view the email i just see the subject line, and couple of the information collected, so please let me know how this issue can be solved, thanks.

    HTML,

    <form method="post" action="contact.php" id="commentform">

    <tr>
    <td class="name"><input type="text" name="nmachine" id="nmachine" class="rform"/>نام دستگاه</td>
    </tr>
    <tr>
    <td class="name"><input type="text" name="bmachine" id="bmachine" class="rform"/>برند دستگاه</td>
    </tr>
    <tr>
    <td class="name"><input type="text" name="zmachine" id="zmachine" class="rform"/>ظرفیت دستگاه</td>
    </tr>
    <tr>
    <td class="name"><input type="text" name="mdmachine" id="mdmachine" class="rform"/>مدل دستگاه</td>
    </tr>
    <tr>
    <td class="name"><input type="text" name="smachine" id="smachine" class="rform"/>سال ساخت دستگاه</td>
    </tr>
    <tr>
    <td><textarea name="t1machine" id="t1machine" cols="80" rows="2" class="rform">
    </textarea>توضیحات اضافی</td>
    </tr>

    <tr>
    <td class="name"><input type="text" name="yname" id="yname" class="rform"/>نام و نام خانوادگی شما</td>
    </tr>
    <tr>
    <td class="name"><input type="text" name="yp" id="yp" class="rform"/>تلفن همراه</td>
    </tr>
    <tr>
    <td class="name"><input type="text" name="ym" id="ym" class="rform"/>تلفن ثابت</td>
    </tr>
    <tr>
    <td class="name"><input type="text" name="fax" id="fax" class="rform"/>فکس</td>
    </tr>
    <tr>
    <td class="name"><input type="text" name="email" id="email" class="rform"/>ایمیل</td>
    </tr>
    <tr>
    <td><textarea name="t2machine" id="t2machine" cols="80" rows="2" class="rform">
    </textarea>توضیحات اضافی</td>
    </tr>
    <tr>
    <td><input type="submit" value=" ارسال فرم" name="submit" id="submit" class="rform"/><input type="reset" value="ترخیص فرم" name="reset" id="reset" class="rform"/></td>
    </tr>
    </form>
    PHP,


    <?php
    $nmachine = $_POST ['nmachine'] ;
    $bmachine = $_POST ['bmachine'] ;
    $zmachine = $_POST ['zmachine'] ;
    $mdmachine = $_POST ['mdmachine'];
    $smachine = $_POST ['smachine'];
    $t1machine = $_POST ['t1machine'];
    $yname = $_POST ['yname'];
    $yp = $_POST ['yp'];
    $ym = $_POST ['ym'];
    $fax = $_POST ['fax'];
    $email = $_POST ['email'];
    $t2machine = $_POST ['t2machine'];
    $submit = $_POST ['submit'] ;

    $sendTo = "myemail@gmail.com";
    $subject = "company form";
    $message = "$t1machine
    from $yname, $yp";

    $headers = "From: $yname <$email> \r\n";
    $headers .= "X-Mailer:PHP/\r\n";
    $headers .= "MIME-Version:1.0\r\n";
    $headers .= "Content-type:text/plain; charset=iso-8859-1\r\n";

    if(isset($submit)){
    $sent = mail($sendTo, $subject, $message, $headers);

    if ($sent) {
    header("location:./thankyou.html");
    }else{
    echo "Message Failed";
    }

    }
    ?>
  • i think is the mail function structure.
    mail is structured like that : to, subject, message.
    After message you can put additional headers informations.
    so i think is better do like that ( this is a very quick and basic way ) :


    <?php

    $field1 = $_POST ['field1'];
    $field2 = $_POST ['field2'];

    if(isset($field1) && isset($field2)){
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html;charset=utf-8' . "\r\n";
    $headers .= "From:Your site name<mail address for example>";
    $to= 'your email';
    $subject= 'Email from etc...';
    $message= "$field1 is the first field you type. $field2 is the second one.";
    if(@mail($to, $subject, $message,$headers)){
    header("Location: thanks.html");
    }
    else{
    header("Location: error.html");
    }
    }else{
    echo 'complete the form.';
    }

    ?>



    i hope this is correct and helps you! :)

    bye