troubleshooting Question

Broken Code

Avatar of miloudi
miloudi asked on
30 Comments2 Solutions468 ViewsLast Modified:
Hello To all of you,

Pleas forgive me if i posted this in the wrong area, but i really need your help guys:
I setup a form to get info from users, display the info on the same page, email it to me and write it to a file:
Here is  my code.

      $submit = $_POST['submit'];
      $emailAddress = $_POST['emailAddress'];
      $comments = $_POST['comments'];


      $name = $_POST['name'];
      $contact_recipient_id = $_POST['contact_recipient_id'];
      $subject = $_POST['subject'];
      $message = $_POST['message'];
      $option = $_POST['option'];


               if ($_SERVER['REQUEST_METHOD'] != 'POST'){
                  $me = $_SERVER['PHP_SELF'];
      <form action="<?php echo $me;?>" method='post'>
            <table class="info">


            <tr><td>Title:</td><td><input type="radio" name="title" value="Mr"/>Mr
            <input type="radio" name="title" value="Mrs"/>Mrs
            <input type="radio" name="title" value="Miss"/>Miss</td></tr>
            <tr><td id="fn">*First Name:</td><td><input type="text" name="fName" /></td></tr>

            <tr><td id="ln">*Last Name:</td><td><input type="text" name="lName" /></td></tr>

            <tr><td id="ss">*Social Security Number:</td><td><input type="text" name="ssn" size="9" maxlength="11"/></td></tr>

            <tr><td id="ag">*Age:</td><td><input type="text" name="age" size="1" maxlength="3"/></td></tr>

            <tr><td>Gender:</td><td><select name="gender">
            <option value="male">M</option>
            <option value="female">F</option>

            <tr><td id="ea">*Email Address:</td><td><input type="text" name="email" /></td></tr>

            <tr><td id="pn">*Phone Number:</td><td><input type="text" name="phone" size="11" maxlength="13"/></td></tr>

            <tr><td>Comments Or Questions:</td>

            <td><textarea name="data" rows="4" cols="50"></textarea></td></tr>

            <tr><td><input type="submit" value="Submit" name="submit"/>
            <input type="reset" value="Reset" name="reset" /></td></tr>


               } else {
                  $recipient = '';
            $subject = 'Just to say Hi';
            $from = stripslashes($_POST['fName']);
              $msg = "Message from: $from\n\n".stripslashes($_POST['MsgBody']);
                if (mail($recipient, $subject, $msg))
                echo nl2br("<b>Message Sent:</b>
                  To: $recipient
                     Subject: $subject
         echo "Message failed to send";

      // Open and write to a file
      $myFile = "testfile.txt";
      $fh = fopen($myFile, 'a') or die("can't open file");
$string = $name."\t"."\t".$ssn."\t".$email."\t".$subject."\t".$message."\n";      
      fwrite($fh, $string);


I don't understand how you can post and email the form at the same time. Originally what i did is i sent the data to another php form and then wrote from there to a file. But it is not the way it should be. Any help will be appreciated.
Also if i want to write to a file, i need to setup another from, don't i?


Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 30 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 30 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros