I have a small app that uploads a file and then emails the uploaded file and other text box fields. My problem is that the file isn't being attached and the message text is being displayed twice in the email body. The image gets uploaded because I see it on the server.
Here is my emailing code:
I've tried using the directory path, I've tried with and without a trailing /. I've tried with the filename in the $fileatt variable and without it. I've tried using the http directory path and the path. None seem to attach the picture to be viewed my the email recipient. Also, I can't figure out why it sends the body of the message twice in the email.
Thanks in advance,
Here is my emailing code:
Code:
//*****Email Info
$email_to = "email@domain.com";
$email_from = "email@domain.com"; $email_subject = "Crystal Order ID: #" . $sOrderID;
$email_message = "Customer Name: " . $custFName . " " . $custLName . "\n"; $email_message .= "Email Address: " . $custEmail . "\n";
$email_message .= "Custom Text Line 1: " . $sCustText1 . " in " . $sTextFont1 . " Font Type\n";
$email_message .= "Custom Text Line 2: " . $sCustText2 . " in " . $sTextFont2 . " Font Type\n";
$email_message .= "Coupon Code: " . $sCouponCode . "\n";
$email_message .= "Crystal Size: " . $sCrystalSize . "\n";
$email_message .= "Crystal Selected: " . $sCrystalSKU . "\n";
$email_message .= "\nPlease Send To:\n" . $custStreet . "\n" . $custCity . ", " . $custState . " " . $custZip . "\n";
$email_message .= "\nIs this a residential address: " . $residential . "\n";
$email_message .= "\n\nEnd Email\n";
//*****Email Construction
$headers = "From: ".$email_from;
$headers .= "\r\nBCC: other@domain.net\r\n";
$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}\"";
$email_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" .
$email_message . "\n\n";
//********************************************** First File ********************************************/
$fileatt = "/directory/path/of/uploads/";
$fileatt_type = "image/jpeg";
$fileatt_name = $sFileUpload;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$data = chunk_split(base64_encode($data));
$email_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";
unset($data);
unset($file);
unset($fileatt);
unset($fileatt_type);
unset($fileatt_name);
$ok = @mail($email_to, $email_subject, $email_message, $headers);
I've tried using the directory path, I've tried with and without a trailing /. I've tried with the filename in the $fileatt variable and without it. I've tried using the http directory path and the path. None seem to attach the picture to be viewed my the email recipient. Also, I can't figure out why it sends the body of the message twice in the email.
Thanks in advance,