hello...check this:
$to = "somw@some.com";
$from = $_POST['email'];
$subject = "Resume Details";
$mail_body = "message body";
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];
//echo $fileatt;
//echo "".$fileatt_type;
//echo "".$fileatt_name;
//exit;
$headers = "From: $from";
if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
$semi_rand = md5( time() );
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$mail_body = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$mail_body . "\n\n";
$data = chunk_split( base64_encode( $data ) );
$mail_body .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
$ok = @mail($to, $subject, $mail_body, $headers);
fclose($file);
}
Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
Just edited, anyway, nice posted Shanti :)
index.html
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Send email with Attachment</title>
</head>
<body>
<h2>Send email with Attachment</h2>
<form action="process.php" method="post" enctype="multipart/form-data">
To:<input type="text" name="email" />
File: <input type="file" name="file" id="file" />
<input type="submit" name="submit" value="Sent" />
</form>
</body>
</html>
process.php
<?php
$from = "you@domain.com";
$to = $_POST['email'];
$subject = "Uploaded file";
$mail_body = "Message body";
$fileatt = $_FILES['file']['tmp_name'];
$fileatt_type = $_FILES['file']['type'];
$fileatt_name = $_FILES['file']['name'];
$headers = "From: $from";
if (is_uploaded_file($fileatt))
{
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt, 'rb');
$data = fread($file, filesize($fileatt));
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
$mail_body = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $mail_body . "\n\n";
$data = chunk_split( base64_encode($data));
$mail_body .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n";
$ok = @mail($to, $subject, $mail_body, $headers);
if($ok)
echo "Email sent :)";
else
echo "Failed !!!";
fclose($file);
}
?>
dean8710
Junior Poster in Training
54 posts since Jul 2011
Reputation Points: 7
Solved Threads: 2