I'm using PHP to send a multi-part MIME mail with attachments. It all works fine, but for some reason, every mail I send has an additional attachment named...
ATXXXXX.ATT (where the X's are integers) It has a size (very small... 78B in the example I'm about to post), but when I open it with emacs it looks empty.
I don't care so much... but would like to drop it if possible. Here's my code...
Called with...
ATXXXXX.ATT (where the X's are integers) It has a size (very small... 78B in the example I'm about to post), but when I open it with emacs it looks empty.
I don't care so much... but would like to drop it if possible. Here's my code...
Code:
function sendMail($subject, $to, $attachments, $text) {
$mime_boundary = "<<<--==+X[".md5(time())."]";
$headers .= "From: Self Evaluation Form\r\n";
$headers .= "To: <$to>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed;\r\n";
$headers .= ' boundary="'.$mime_boundary.'"';
$body = "--".$mime_boundary."\r\n";
$body .= 'Content_Type: text/plain; charset="us-ascii"'."\r\n";
$body .= 'Content-Transfer-Encoding: 7bit'."\r\n";
$body .= "$text\r\n";
if (is_array($attachments)) {
foreach($attachments as $filename=>$attachment) {
$body .= "--".$mime_boundary."\r\n";
$body .= "Content-Type: application/octet-stream;\r\n";
$body .= ' name="'.$filename.'"'."\r\n";
$body .= "Content-Transfer-Encoding: quoted-printable\r\n";
$body .= "Content-Disposition: attachment;\r\n";
$body .= ' filename="'.$filename.'"'."\r\n";
$body .= "\r\n";
$body .= $attachment;
$body .= "\r\n";
$body .= "--".$mime_boundary."\r\n";
}
echo '<pre>';
print_r($body);
$ok = mail($to, $subject, $body, $headers);
}
}
Code:
$attachments['test1.txt']="Woo hoo moo foo";
$body = "\r\nTesting 1 2 3";
sendMail("Testing this attachment stuffs", "youremail@here.com", $attachments, $body);