I have a problem. I have users uploading a file via a form. I would then like to have the file attached to an email. Here is my code so far, please help!....
if (isset($_POST['Submit'])) { //Handle the Form.
$db="xxxxxxx";
$connect=mysql_connect("localhost","xxxxxxx","xxxxxxxxx");
if(!$connect)die("Couldn't connect to MySQL");
mysql_select_db($db,$connect)or die("Select DB Error: ".mysql_error());
//Add the info to database.
$query="INSERT INTO checks VALUES (0,'$requested_by',NOW(),'$committee','$amount','$pay_to','$address','$city','$zip','$date_needed','$description','{$_FILES['upload']['name']}', '{$_FILES['upload']['size']}', '{$_FILES['upload']['type']}', NOW())";
$result=mysql_query($query);
if($result) {
//move the file over.
if(move_uploaded_file($_FILES['upload']['tmp_name'], "../parents/uploads/{$_FILES['upload']['name']}")) {
echo '<p>Your check request has been submitted. The attached file has been uploaded</p>';
} else {
echo '<p>Your check request has been submitted. The file could not be moved.</p>';
}
} else { //if the query did not run OK.
echo '<p>Your submission could not be processed due to a system error. We apologize for any inconvenience.</p>';
}
//send an email
$body="The following person has submitted a check request on the Explorer website:
NAME='{$_POST['requested_by']}',
ADDRESS='{$_POST['address']}',
CITY='{$_POST['city']}',
ZIP CODE='{$_POST['zip']}',
COMMITTEE='{$_POST['committee']}',
AMOUNT='{$_POST['amount']}',
MAKE CHECK PAYABLE TO='{$_POST['pay_to']}',
DATE NEEDED='{$_POST['date_needed']}',
COMMENTS='{$_POST['description']}'
Please review this and submit an approval to the Treasurer via email at [email]xxxxxxxxx@xxxxxx.xxx[/email]
Thank you.";
mail ('xxxxxxx@xxxxxx.xxx', 'Check Request Form - Explorer Website', $body, 'From: [email]admin@explorerpreschool.org[/email]', 'Attachment: $attachment');
mysql_close(); //close the database connection.
} else {
?>
<p class="text">Please fill out the following form to have your check request processed.</p>
<form enctype="multipart/form-data" name="check_request" id="check_request" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table width="100%" border="0" cellspacing="0" cellpadding="3" summary="check request form">
<tr>
<td valign="top" class="table_right">Requested by: </td>
<td valign="top" class="text"><input name="requested_by" type="text" id="requested_by" size="60" /></td>
</tr>
<tr>
<td valign="top" class="table_right">Committee:</td>
<td valign="top" class="text"><select name="committee" id="committee">
<option value="xxxxxxxxxxxx">President</option>
<option value="xxxxxxxxxxxx">Vice President</option>
<option value="xxxxxxxxxxxx">Secretary</option>
<option value="xxxxxxxxxxxx">Treasurer</option>
<option value="xxxxxxxxxxxx">Membership</option>
<option value="xxxxxxxxxxxx">Maintenance</option>
<option value="xxxxxxxxxxxx">Publicity</option>
<option value="xxxxxxxxxxxx">SCVC Rep</option>
<option value="xxxxxxxxxxxx">Scrip</option>
<option value="xxxxxxxxxxxx">Fundraising</option>
<option value="xxxxxxxxxxxx">Adult Education</option>
<option value="xxxxxxxxxxxx">Children's Education</option>
<option value="xxxxxxxxxxxx">Business Manager</option>
<option value="xxxxxxxxxxxx">Social</option>
</select></td>
</tr>
<tr>
<td valign="top" class="table_right">Amount:</td>
<td valign="top" class="text"><input name="amount" type="text" id="amount" size="10" /></td>
</tr>
<tr>
<td valign="top" class="table_right">Payable to: </td>
<td valign="top" class="text"><input name="pay_to" type="text" id="pay_to" size="60" /></td>
</tr>
<tr>
<td valign="top" class="table_right">Address:</td>
<td valign="top" class="text"><input name="address" type="text" id="address" size="60" /></td>
</tr>
<tr>
<td valign="top" class="table_right">City:</td>
<td valign="top" class="text"><input name="city" type="text" id="city" size="60" /></td>
</tr>
<tr>
<td valign="top" class="table_right">Zip Code: </td>
<td valign="top" class="text"><input name="zip" type="text" id="zip" size="15" /></td>
</tr>
<tr>
<td valign="top" class="table_right">Date Needed by: </td>
<td valign="top" class="text"><input name="date_needed" type="text" id="date_needed" size="15" /></td>
</tr>
<tr>
<td valign="top" class="table_right">Description of Purchase: </td>
<td valign="top" class="text"><textarea name="description" cols="60" rows="5" id="description"></textarea></td>
</tr>
<tr>
<td valign="top" class="table_right"> </td>
<td valign="top" class="text"> </td>
</tr>
<tr>
<td valign="top" class="table_right"> </td>
<td valign="top" class="text">Receipts must be attached in PDF form or hard copies to Treasurer's mailbox.</td>
</tr>
<tr>
<td valign="top" class="table_right"> </td>
<input type="hidden" name="MAX_FILE_SIZE" value="100000000" />
<td valign="top" class="text">File: <input name="upload" type="file" size="40" /></td>
</tr>
<tr>
<td valign="top" class="table_right"> </td>
<td valign="top" class="text"> </td>
</tr>
<tr>
<td valign="top" class="table_right"> </td>
<td valign="top" class="text"><input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
</form>
<?php
}
?>