GazzaMataz
11-02-2009, 11:54 AM
<?php
//Set up email and attachment details
$to = "myemail@email.com";
$subject = "Application Form";
// 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'];
$job = $_POST["job"];
$salutation = $_POST["salutation"];
$fromename = $_POST["fromname"];
$address = $_POST["address"];
$phone = $_POST["phone"];
$fromemail = $_POST["fromemail"];
$about = $_POST["about"];
//Form contents
$message = "You have a job enquiry: $name \n
Job Required: $job \n
Salutation: $salutation \n
From: $fromename \n
Address: $address \n
Telephone: $phone \n
E-mail: $fromemail \n
About yourself: $about";
//Read in the attachment
if (file_exists($tmp_name)){
if(is_uploaded_file($tmp_name)){
$file = fopen($tmp_name, 'rb');
$data = fread($file, filesize($tmp_name));
fclose($file);
//Encode it and split it into acceptable length lines
$data = chunk_split(base64_encode($data));
}
//Add the MIME content
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x".md5(mt_rand())."x";
$headers = "From: $fromemail\r\n".
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
"boundary=\"{$mime_boundary}\"";
//Message header
$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";
// Insert boundary to indicate we're starting the attachment
// 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=\"{$name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
//Send the e-mail
mail($to, $subject, $message, $headers);
?>
Can anyone help me get this working? If I submit it without an attachment it works, as soon as I add an attachment it sends it but nothing appears in the sent e-mail. I think it is something to d with the uploading of the files…
Any help greatly appreciated!
//Set up email and attachment details
$to = "myemail@email.com";
$subject = "Application Form";
// 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'];
$job = $_POST["job"];
$salutation = $_POST["salutation"];
$fromename = $_POST["fromname"];
$address = $_POST["address"];
$phone = $_POST["phone"];
$fromemail = $_POST["fromemail"];
$about = $_POST["about"];
//Form contents
$message = "You have a job enquiry: $name \n
Job Required: $job \n
Salutation: $salutation \n
From: $fromename \n
Address: $address \n
Telephone: $phone \n
E-mail: $fromemail \n
About yourself: $about";
//Read in the attachment
if (file_exists($tmp_name)){
if(is_uploaded_file($tmp_name)){
$file = fopen($tmp_name, 'rb');
$data = fread($file, filesize($tmp_name));
fclose($file);
//Encode it and split it into acceptable length lines
$data = chunk_split(base64_encode($data));
}
//Add the MIME content
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x".md5(mt_rand())."x";
$headers = "From: $fromemail\r\n".
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
"boundary=\"{$mime_boundary}\"";
//Message header
$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";
// Insert boundary to indicate we're starting the attachment
// 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=\"{$name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
//Send the e-mail
mail($to, $subject, $message, $headers);
?>
Can anyone help me get this working? If I submit it without an attachment it works, as soon as I add an attachment it sends it but nothing appears in the sent e-mail. I think it is something to d with the uploading of the files…
Any help greatly appreciated!