Jump to content

send email from form input help


nouse4one

Recommended Posts

I am stumped here, can not figure out a efficient way to collect all the data on this page and send it to my to user's id number.

I am trying to format the email to include question #1 and then next to it radio1 (answer yes/no) , question#2 and so on followed by the viewers input from the last part of the form. Does any one know of some thing im missing here?

<?php
  session_start();

  // If the session vars aren't set, try to set them with a cookie
  if (!isset($_SESSION['user_id'])) {
    if (isset($_COOKIE['user_id']) && isset($_COOKIE['username'])) {
      $_SESSION['user_id'] = $_COOKIE['user_id'];
      $_SESSION['username'] = $_COOKIE['username'];
    }
  }
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Social Filter - View Profile</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
  <h3>View Profile</h3>
<font size="2">
<?php
  require_once('appvars.php');
  require_once('connectvars.php');

  // Make sure the user is logged in before going any further.
  if (!isset($_SESSION['user_id'])) {
    echo '<a href="signup.php">Create your own account</a>.</p>';
  }
  else {
    echo('<p class="login">You are logged in as ' . $_SESSION['username'] . '. <a href="logout.php">Log out</a>.</p>');
  }

  // Connect to the database
  $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

  // Grab the profile data from the database
  if (!isset($_GET['user_id'])) {
    $query = "SELECT username, first_name, last_name, gender, birthdate, city, state, picture, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15, q16, q17, q18, q19, q20 FROM mismatch_user WHERE user_id = '" . $_SESSION['user_id'] . "'";
  }
  else {
    $query = "SELECT username, first_name, last_name, gender, birthdate, city, state, picture, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15, q16, q17, q18, q19, q20  FROM mismatch_user WHERE user_id = '" . $_GET['user_id'] . "'";
  }
  $data = mysqli_query($dbc, $query);

  if (mysqli_num_rows($data) == 1) {
    // The user row was found so display the user data
    $row = mysqli_fetch_array($data);
    echo '<table cellpadding="0" cellspacing="0" border="0"><TR><TD> ';
    if (!empty($row['picture'])) {
      echo '<table  cellpadding="0" cellspacing="0" border="1"><TR><td class="label">Picture:</td><td><img src="' . MM_UPLOADPATH . $row['picture'] .
        '" width="120" height="140" alt="Profile Picture" /></td></tr></table></td><td>';
    }
    if (!empty($row['username'])) {
      echo '<table cellpadding="1" cellspacing="0" border="0"><TR><td class="label">Username:</td><td>' . $row['username'] . '</td></tr>';
    }
    if (!empty($row['first_name'])) {
      echo '<tr><td class="label">First name:</td><td>' . $row['first_name'] . '</td></TR>';
    }
    if (!empty($row['last_name'])) {
      echo '<tr><td class="label">Last name:</td><td>' . $row['last_name'] . '</td></TR>';
    }
    if (!empty($row['gender'])) {
      echo '<tr><td class="label">Gender:</td><td>';
      if ($row['gender'] == 'M') {
        echo 'Male';
      }
      else if ($row['gender'] == 'F') {
        echo 'Female';
      }
      else {
        echo '?';
      }
      echo '</td></tr>';
    }
    if (!empty($row['birthdate'])) {
      if (!isset($_GET['user_id']) || ($_SESSION['user_id'] == $_GET['user_id'])) {
        // Show the user their own birthdate
        echo '<tr><td class="label">Birthdate:</td><td>' . $row['birthdate'] . '</td></tr>';
      }
      else {
        // Show only the birth year for everyone else
        list($year, $month, $day) = explode('-', $row['birthdate']);
        echo '<tr><td class="label">Year born:</td><td>' . $year . '</td></tr>';
      }
    }
    if (!empty($row['city']) || !empty($row['state'])) {
      echo '<tr><td class="label">Location:</td><td>' . $row['city'] . ', ' . $row['state'] . '</td></tr>';
    }
    echo '</td></tr></table></td></Tr></table><hr></font><FONT color="#666666" size="1" face="Courier"><table cellpadding="20" cellspacing="0" border="0"><tr><td>';
    if (!isset($_GET['user_id']) || ($_SESSION['user_id'] == $_GET['user_id'])) {
      echo '<p>Would you like to <a href="editprofile.php">edit your profile</a>?</p>';
    }
  } // End of check for a single row of user results
  else {
    echo '<p class="error">There was a problem accessing your profile.</p>';
  }
if (!empty($row['q1'])) {
      echo '1. ' . $row['q1'] . '<BR><input type="radio" name="radio1" id="yes1" value="yes" />
        <label for="yes1">YES</label> or <input type="radio" name="radio1" id="no1" value="no" />
      <label for="no1">NO</label><BR>';
      }
  else {
      echo ' User has not made a application yet...<BR>';
}

if (!empty($row['q2'])) {
      echo '2. ' . $row['q2'] . '<BR><input type="radio" name="radio2" id="yes2" value="yes" />
        <label for="yes2">YES</label> or <input type="radio" name="radio2" id="no2" value="no" />
      <label for="no2">NO</label><BR>';
      }
  else {
      echo ' <BR>';
}

if (!empty($row['q3'])) {
      echo '3. ' . $row['q3'] . '<BR><input type="radio" name="radio3" id="yes3" value="yes" />
        <label for="yes3">YES</label> or <input type="radio" name="radio3" id="no3" value="no" />
      <label for="no3">NO</label><BR>';
      }
  else {
      echo '<BR>';
}

if (!empty($row['q4'])) {
      echo '4. ' . $row['q4'] . '<BR><input type="radio" name="radio4" id="yes4" value="yes" />
        <label for="yes4">YES</label> or <input type="radio" name="radio4" id="no4" value="no" />
      <label for="no4">NO</label><BR>';
      }
  else {
      echo '<BR>';
}

if (!empty($row['q5'])) {
      echo '5. ' . $row['q5'] . '<BR><input type="radio" name="radio5" id="yes5" value="yes" />
        <label for="yes5">YES</label> or <input type="radio" name="radio5" id="no5" value="no" />
      <label for="no5">NO</label><BR>';
      }
  else {
      echo '<BR>';
}

if (!empty($row['q6'])) {
      echo '6. ' . $row['q6'] . '<BR><input type="radio" name="radio6" id="yes6" value="yes" />
        <label for="yes6">YES</label> or <input type="radio" name="radio6" id="no6" value="no" />
      <label for="no6">NO</label><BR>';
      }
  else {
      echo '<BR>';
}

if (!empty($row['q7'])) {
      echo '7. ' . $row['q7'] . '<BR><input type="radio" name="radio7" id="yes7" value="yes" />
        <label for="yes7">YES</label> or <input type="radio" name="radio7" id="no7" value="no" />
      <label for="no7">NO</label><BR>';
      }
  else {
      echo '<BR>';
}

if (!empty($row['q8'])) {
      echo '8. ' . $row['q8'] . '<BR><input type="radio" name="radio8" id="yes8" value="yes" />
        <label for="yes8">YES</label> or <input type="radio" name="radio8" id="no8" value="no" />
      <label for="no8">NO</label><BR>';
      }
  else {
      echo '<BR>';
}

if (!empty($row['q9'])) {
      echo '9. ' . $row['q9'] . '<BR><input type="radio" name="radio9" id="yes9" value="yes" />
        <label for="yes9">YES</label> or <input type="radio" name="radio9" id="no9" value="no" />
      <label for="no9">NO</label><BR>';
      }
  else {
      echo '<BR>';
}

if (!empty($row['q10'])) {
      echo '10. ' . $row['q10'] . '<BR><input type="radio" name="radio10" id="yes10" value="yes" />
        <label for="yes10">YES</label> or <input type="radio" name="radio10" id="no10" value="no" />
      <label for="no10">NO</label><BR></td><TD>';
      }
  else {
      echo '<BR></td><td>';
}

if (!empty($row['q11'])) {
      echo '11. ' . $row['q11'] . '<BR><input type="radio" name="radio11" id="yes11" value="yes" />
        <label for="yes11">YES</label> or <input type="radio" name="radio11" id="no11" value="no" />
      <label for="no11">NO</label><BR>';
      }
  else {
      echo '<BR>';
}

if (!empty($row['q12'])) {
      echo '12. ' . $row['q12'] . '<BR><input type="radio" name="radio12" id="yes12" value="yes" />
        <label for="yes12">YES</label> or <input type="radio" name="radio12" id="no12" value="no" />
      <label for="no12">NO</label><BR>';
      }
  else {
      echo '<BR>';
}

if (!empty($row['q13'])) {
      echo '13. ' . $row['q13'] . '<BR><input type="radio" name="radio13" id="yes13" value="yes" />
        <label for="yes13">YES</label> or <input type="radio" name="radio13" id="no13" value="no" />
      <label for="no13">NO</label><BR>';
      }
  else {
      echo '<BR>';
}

if (!empty($row['q14'])) {
      echo '14. ' . $row['q14'] . '<BR><input type="radio" name="radio14" id="yes14" value="yes" />
        <label for="yes14">YES</label> or <input type="radio" name="radio14" id="no14" value="no" />
      <label for="no14">NO</label><BR>';
      }
  else {
      echo '<BR>';
}

if (!empty($row['q15'])) {
      echo '15. ' . $row['q15'] . '<BR><input type="radio" name="radio15" id="yes15" value="yes" />
        <label for="yes15">YES</label> or <input type="radio" name="radio15" id="no15" value="no" />
      <label for="no15">NO</label><BR>';
      }
  else {
      echo '<BR>';
}

if (!empty($row['q16'])) {
      echo '16. ' . $row['q16'] . '<BR><input type="radio" name="radio16" id="yes16" value="yes" />
        <label for="yes16">YES</label> or <input type="radio" name="radio17" id="no16" value="no" />
      <label for="no16">NO</label><BR>';
      }
  else {
      echo '<BR>';
}

if (!empty($row['q17'])) {
      echo '17. ' . $row['q17'] . '<BR><input type="radio" name="radio17" id="yes17" value="yes" />
        <label for="yes17">YES</label> or <input type="radio" name="radio17" id="no17" value="no" />
      <label for="no17">NO</label><BR>';
      }
  else {
      echo '<BR>';
}

if (!empty($row['q18'])) {
      echo '18. ' . $row['q18'] . '<BR><input type="radio" name="radio18" id="yes18" value="yes" />
        <label for="yes18">YES</label> or <input type="radio" name="radio18" id="no18" value="no" />
      <label for="no18">NO</label><BR>';
      }
  else {
      echo '<BR>';
}
if (!empty($row['q19'])) {
      echo '19. ' . $row['q19'] . '<BR><input type="radio" name="radio19" id="yes19" value="yes" />
        <label for="yes19">YES</label> or <input type="radio" name="radio19" id="no19" value="no" />
      <label for="no19">NO</label><BR>';
      }
  else {
      echo '<BR>';
}
if (!empty($row['q20'])) {
      echo '20. ' . $row['q20'] . '<BR><input type="radio" name="radio20" id="yes20" value="yes" />
        <label for="yes20">YES</label> or <input type="radio" name="radio20" id="no20" value="no" />
      <label for="no20">NO</label><BR></td><td></font></font>';
      }
  else {
      echo '<BR></td><td valign="top"></font></font><FONT color="#000000" size="1">';
}
  mysqli_close($dbc);
?>
<script>

function autotab(original,destination){
if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
destination.focus()
}

</script>
<fieldset>
<legend>Your Contact Information</legend>
</font></font><FONT color="#cccc99" size="2" face="Impact">
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <table width="100%" border="0" cellpadding="2">
    <tr>
      <td><div align="right">
        <label for="vieweremail">Email</label>
      </div></td>
      <td><div align="left">
        <input name="vieweremail" type="text" id="vieweremail" size="35" maxlength="90" />
      </div></td>
    </tr>
    <tr>
      <td><div align="right">
        <label for="veiwername">Name</label>
      </div></td>
      <td><div align="left">
        <input name="veiwername" type="text" id="veiwername" size="35" maxlength="100" />
      </div></td>
    </tr>
    <tr>
      <td><div align="right">
        <label for="viewerphone">Phone Number</label>
      </div></td>
      <td><div align="left">
        <input name="Phone1" type="text" id="phone1" onkeyup="autotab(this, document.form1.phone2)" size="3" maxlength="3" />
        <input name="phone2" type="text" id="phone2" onKeyup="autotab(this, document.form1.phone3)" size="3" maxlength="3" />
        <input name="phone3" type="text" id="phone3" onKeyup="autotab(this, document.form1.viewercomments)" size="4" maxlength="4" />
      </div></td>
    </tr>
    <tr>
      <td><div align="right">
        <label for="viewercomments">Comments</label>
      </div></td>
      <td><div align="left">
        <textarea name="viewercomments" cols="26" rows="4" id="viewercomments"></textarea>
      </div></td>
    </tr>
    <tr>
      <td><div align="right">
        <label for="viewerpic">Your Picture (optional)</label>
      </div></td>
      <td><div align="left">
        <input name="viewerpic" type="file" id="viewerpic" size="22" />
      </div></td>
    </tr>
    <tr>
      <td><div align="right">
        <label for="clear"></label>
        <input type="reset" name="clear" id="clear" value="Clear Form!" />
      </div></td>
      <td><div align="left">
        <label for="submit"></label>
        <input type="submit" name="submit" id="submit" value="Send Email" />
      </div></td>
    </tr>
  </table> 
</form>
</fieldset>
<BR><BR><BR><BR><BR><BR>
</td></tr></table>
</body> 
</html>

 

Here is the send mail script im using.... trying to anyways.

<?php
  require_once('appvars.php');
  require_once('connectvars.php');

  // Connect to the database
  $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

  if (isset($_POST['submit'])) {
    $from = 'cupid@cupidsomething.com';
    $subject = $_POST['subject'];
    $text = $_POST['q1, q2,q3,q4....ect...etc....cet.....eece.c.'];
    $output_form = false;

    if (empty($subject) && empty($text)) {
      echo 'You forgot the email subject and body text.<br />';
      $output_form = true;
    }

    if (empty($subject) && (!empty($text))) {
      echo 'You forgot the email subject.<br />';
      $output_form = true;
    }

    if ((!empty($subject)) && empty($text)) {
      echo 'You forgot the email body text.<br />';
      $output_form = true;
    }
  }
  else {
    $output_form = true;
  }

  if ((!empty($subject)) && (!empty($text))) {

    $query = "SELECT user_id FROM email_list WHERE user_id = '$user_id';
    $result = mysqli_query($dbc, $query)
      or die('Error querying database.');

    while ($row = mysqli_fetch_array($result)){
      $to = $row['email'];
      $first_name = $row['first_name'];
      $last_name = $row['last_name'];
      $msg = "Dear $first_name $last_name,\n$text";
      mail($to, $subject, $msg, 'From:' . $from);
      echo 'Email sent to: ' . $first_name . '<br />';
    } 

    mysqli_close($dbc);
  }

  if ($output_form) {
?>

Any help would be greeeeatly appreciated. Here is a live example of this at www.interestingspecies.com/mismatch/20

Link to comment
Share on other sites

That last line of code on my emailscript was transferred to this thread my mistake please disregard it.

 

what happens now when i click send?

Absolutely nothing :( i can't figure out a way to collect all the data on the page. And then insert it into the email to my member.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.