Hello,
Need someone help with getting the attachment work. Everything works, but it does not attach file to the email.
Here is my code
<html>
<head>
<title>My email attachment</title>
</head>
<body>
<?php
$turnaround = "1 business day";
$accounts = array(
"Account-1",
"Account-2",
"Account-3",
);
$platforms = array( "Mainframe", "DB2 LUW" );
$types = array( "Service Request / Project", "Consultation / Information Request" );
$priorities = array( "Low", "Medium", "High" );
if ( $_SERVER['REQUEST_METHOD'] == "POST" )
{
if ( $_POST['platform'] == "Mainframe" )
{
$mail_address = "email1@mail.com";
}
else
{
$mail_address = "email2@mail.com";
}
// generate a random string to be used as the boundary marker
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
// store the file information to variables for easier access
$tmp_name = $_FILES['filename']['tmp_name'];
$type = $_FILES['filename']['type'];
$name = $_FILES['filename']['name'];
$size = $_FILES['filename']['size'];
// if the upload succeded, the file will exist
if (file_exists($tmp_name)){
// check to make sure that it is an uploaded file and not a system file
if(is_uploaded_file($tmp_name)){
// open the file for a binary read
$file = fopen($tmp_name,'rb');
// read the file content into a variable
$data = fread($file,filesize($tmp_name));
// close the file
fclose($file);
// now we encode it and split it into acceptable length lines
$data = chunk_split(base64_encode($data));
}
// now we'll build the message headers
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
// next, we'll build the message body
// note that we insert two dashes in front of the
// MIME boundary when we use it
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
// now we'll insert a boundary to indicate we're starting the attachment
// we have to specify the content type, file name, and disposition as
// an attachment, then add the file content and set another boundary to
// indicate that the end of the file has been reached
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
// now we just send the message
mail( $mail_address,
join( " - ", array( $_POST['priority'], $_POST['startdate'], $_POST['enddate'], $_POST['platform'], $_POST['type'], $_POST['account'], $_POST['abstract'] ) ),
"*** This message was sent from an automated service ID. Please do not respond to this message. ***\n\nSYSTEMS\n-------\n" . $_POST['systems'] . "\n\nDBS\n---\n" . $_POST['dbs'] . "\n\nINFO\n----\n" . $_POST['info'] . "\n\nAttachment\n-------\n" . $_FILE[$headers] . $_FILE[$message] ."\n",
join( "\r\n", array( "Reply-To: " . $_POST['email'], "From: nobody@mail.com", "Cc: " . $_POST['email'] ) ) );
}
?>
<p>
Your request has been submitted and you will receive a response within <?= $turnaround ?>.
</p>
<p>
<a href="javascript:history.go(-1)">[Back]</a>
</p>
<?php
}
else
{
?>
<p>
Complete the following form to request service from East Fishkill GDF DB2 DBA support.
</p>
<p>
<table border=1 cellpadding=3>
<tr>
<td>
<ul>
<li><b><font color=#ff0000>Note: This request form is not intended to replace your account's
problem/incident reporting mechanisms.</font></b>
<li><b><font color=#ff0000>All problems should be reported using standard
problem reporting processes.</font></b>
<li><b><font color=#ff0000>Any problems reported using this form will have their
resolution delayed.</font></b>
<li><b><font color=#ff0000>New accounts requests eg. not in the account list below,
should follow the ECAT / NBD process.</font></b>
</ul>
</td>
</tr>
</table>
</p>
<br>
<p>
All fields marked with <font color=#ff0000>*</font> are mandatory.
</p>
<p>
<form name=gdfreq action=<?= $_SERVER['PHP_SELF'] ?> method=POST>
<table>
<tr>
<td><b>Request Abstract<font color=#ff0000>*</font></b></td>
<td><input type=text name="abstract" size=80></td>
</tr>
<tr>
<td><b>Email Address<font color=#ff0000>*</font></b><br><i>(e.g. user@email.com)</i></td>
<td><input type=text name="email" size=80></td>
</tr>
<tr>
<td><b>Request Type<font color=#ff0000>*</font></b></td>
<td>
<select name="type">
<?php
foreach ( $types as $type )
{
?>
<option value="<?= $type ?>"><?= $type ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td><b>Account<font color=#ff0000>*</font></b></td>
<td>
<select name="account">
<?php
foreach ( $accounts as $account )
{
?>
<option value="<?= $account ?>"><?= $account ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td><b>Platform<font color=#ff0000>*</font></b></td>
<td>
<select name="platform">
<?php
foreach ( $platforms as $platform )
{
?>
<option value="<?= $platform ?>"><?= $platform ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td><b>Requested Start Date<font color=#ff0000>*</font></b></td>
<td><input type=text name="startdate" size=80 value="<?= date( "m/d/Y", time() + ( 7 * 86400 ) ); ?>"></td>
</tr>
<tr>
<td><b>Requested Completion Date<font color=#ff0000>*</font></b></td>
<td><input type=text name="enddate" size=80 value="<?= date( "m/d/Y", time() + ( 21 * 86400 ) ); ?>"></td>
</tr>
<tr>
<td><b>Priority<font color=#ff0000>*</font></b></td>
<td>
<select name="priority">
<?php
foreach ( $priorities as $priority )
{
?>
<option value="<?= $priority ?>"><?= $priority ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td><b>Subsystem Name (zOS) or Server Names (LUW)</b></td>
<td><textarea name="systems" cols=80 rows=5></textarea></td>
</tr>
<tr>
<td><b>DATABASE Name(s)</b></td>
<td><textarea name="dbs" cols=80 rows=5></textarea></td>
</tr>
<tr>
<td><b>Additional Information</b></td>
<td><textarea name="info" cols=80 rows=5></textarea></td>
</tr>
</table>
<br>
<TABLE BORDER="0"><TR><TD>
<tr>
<b>Attachment: </b>
<form enctype="multipart/form-data" method="POST">
<p><label for="file">File</label> <input type="file" name="filename" id="file"></p>
</tr>
</FORM>
<P><HR WIDTH="30%"><P>
<br>
<input type=submit value="Submit">
<input type=reset>
</form>
</p>
<?php
}
?>