Still learning PHP, but I originally had this form on an html page, call my php script that sent the form information and an attached file. Wanting to try and combine it all to one file, I have everything working except, it does not attach the file or at least it does not send it. I don't think it is a huge problem, but I can't seem to work it out.
Thank You in advanced.
<?php
$sub = $_GET['sub'];
$sub2 = urlencode($sub); //info from another page that I used to remove spaces
$to = "email@email.com";
if (isset($_POST['email']) &&
isset($_POST['fname']) &&
isset($_POST['lname']) &&
isset($_POST['job']) &&
isset($_POST['addition']))
{
$replyTo = $_POST['email'];
$from = $_POST['fname'] . " " . $_POST['lname'];
$job = $_POST['job'];
$subject = "Application for : " . $job;
$message = stripslashes("Name : " . $from . "\r\n\r\n" . "Email : " . $_POST['email'] . "\r\n\r\n" . "Job : " . $job . "\r\n\r\n" . "Additional Information : " . $_POST['addition'] . "\r\n\r\n");
// Obtain file upload vars
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];
$headers = "From: " . $from . "\r\nReply-To: " . $replyTo;
if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
"boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\r\n\r\n" .
"--{$mime_boundary}\r\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\r\n" .
"Content-Transfer-Encoding: 7bit\r\n\r\n" .
$message . "\r\n\r\n";
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
// Add file attachment to the message
$message .= "--{$mime_boundary}\r\n" .
"Content-Type: {$fileatt_type};\r\n" .
" name=\"{$fileatt_name}\"\r\n" .
"Content-Disposition: attachment;\r\n" .
"filename=\"{$fileatt_name}\"\r\n" .
"Content-Transfer-Encoding: base64\r\n\r\n" .
$data . "\r\n\r\n" .
"--{$mime_boundary}--\r\n";
}
// Send the message
$ok = @mail($to, $subject, $message, $headers);
$theResults = <<<EOD
<html>
<head>
<title>The test Page </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
background-color: #f1f1f1;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #666666;
text-decoration: none;
}
-->
</style>
</head>
<div>
<div align="left">Thank you for your interest! Your email will be answered very soon!</div>
</div>
</body>
</html>
EOD;
echo "$theResults";
die();
}
echo <<<_END
<form action="apply.php" method="post"><pre>
Job Applying for : $sub
<input type="hidden" name="job" value=$sub2 />
First Name : <input type="text" name="fname" />
Last Name : <input type="text" name="lname" />
Email : <input type="text" name="email" />
Upload Resume ( pdf or doc ) : <input type="file" name="fileatt"/>
Additional Information :
<textarea name="addition" rows="15" cols="50" ></textarea>
<input type="submit" value="Submit Resume" />
</pre></form>
_END;
?>