I recently have been put the the task of making a form which sends an email with an attachment.
This works fine on our company server, but not on the one I need it to. I am talking file sizes of 6kb just don't attach properly.
Emails are showing up, but the attachments are 300 bytes aprox!?!?
I have been researching high and low trying to figure out why this happens and I just can't figure it out. Here is the code for what its worth. since this works on other servers, i doubt its the code.
max_execution_time = 30
max_input_time = 60
memory_limit = 128
upload_max_filesize = 2m
post_max_size = 8m
Error reporting is on E_ALL and im not getting any notices!?
Code: Select all
<?php
// Read POST request params into global vars
$to = "me@somewhere.com";
$replyTo = $_POST['email'];
$from = $_POST['firstname'] . " " . $_POST['lastname'];
$subject = "Job Application Submission";
//
$action = "send";
$todo = "mail";
// Obtain file upload vars
$fileatt = $_FILES['cv_attachment']['tmp_name'];
$fileatt_type = $_FILES['cv_attachment']['type'];
$fileatt_name = $_FILES['cv_attachment']['name'];
$fileatt_size = $_FILES['cv_attachment']['size'];
//echo "File size is: $fileatt_size";
//
intval($fileatt_size);
//
if($fileatt_size > 2000000){
header('Location: job-form.php?response=File size must be less than 2mb.');
$confirm = "false";
}
//
$first_name = $_REQUEST['first_name'];
$last_name = $_REQUEST['last_name'];
$address_1 = $_REQUEST['address_1'];
$address_2 = $_REQUEST['address_2'];
$suburb = $_REQUEST['suburb'];
$state = $_REQUEST['state'];
$postcode = $_REQUEST['postcode'];
$phone = $_REQUEST['phone'];
$mobile = $_REQUEST['mobile'];
$email = $_REQUEST['email'];
$interested = $_REQUEST['interested'];
$applying = $_REQUEST['applying'];
$work_type = $_REQUEST['work_type'];
$comments = $_REQUEST['comments'];
//
$message = "Name: $first_name $last_name\n
Address 1: $address_1\n
Address 2: $address_2\n
Suburb: $suburb\n
State: $state\n
Postcode: $postcode\n
Phone: $phone\n
Mobile: $mobile\n
Email: $email\n
Position of interest: $interested\n
Company of interest: $applying\n
Work Type: $work_type\n
General Comments: $comments";
$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));
//$data = implode('', file($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\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the plain message
$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";
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
// Add file attachment to the message
$message .= "--{$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";
}
// Send the message
if($confirm != "false"){
mail($to, $subject, $message, $headers);
}
?>Cheers,
Doug