I’m attempting to allow email attachments of images that people want to send to a client.
In the test environment, this worked, but when uploaded to GoDaddy, I began getting this error when attempting to open the received attachment:
[I]Error interpreting JPEG image file (Not a JPEG file: starts with 0x0b 0x0b)
[/I]Below is the code that attaches the image:
multi_attach_mail($to, $_FILES['attachment'], $_POST);
function multi_attach_mail($to, $files, $post)
{
print_r($files);
// email fields: to, from, subject, and so on
// boundary
$email = $post['email'];
$exposure = $post['exposure'];
$from = 'Files attach <'.$email.'>';
$mime_boundary = 'x'.md5(time()).'x';
$message = 'Submitted: '.date("Y.m.d H:i:s").'
'.$post['firstname'].' '.$post['lastname'].' has sent in a photo to be made/kept '.$exposure.'
';
$subject = date("d-M H:i").' Submitted photo to make '.$exposure;
// headers for attachment
$headers .= 'From: '.$from.'
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary='.$mime_boundary.'
';
// multipart boundary
$message .= '--'.$mime_boundary.'
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
'.$message.'
';
// preparing attachments
if(is_file($files['tmp_name'])):
$message .= '--'.$mime_boundary.'
';
$fp = @fopen($files['tmp_name'], "rb");
$data = @fread($fp, $files['size']);
@fclose($fp);
$attachment = chunk_split(base64_encode($data));
$message .= 'Content-Type: '.$files['type'].'; name="'.basename($files['name']).'"
Content-Description: '.basename($files['name']).'
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="'.basename($files['name']).'"; size='.$files['size'].';
'.$attachment.'
';
endif;
$message .= '--'.$mime_boundary.'--';
$ok = @mail($to, $subject, $message, $headers);
if($ok):
return true;
else:
return false;
endif;
}
Because it worked in the test environment, but not production, I have to wonder if there is something different about GoDaddy’s configurations?
Don’t tell me not to use GoDaddy; it’s not an option.
Any help is greatly appreciated.