Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MIME question

Status
Not open for further replies.

skiflyer

Programmer
Joined
Sep 24, 2002
Messages
2,213
Location
US
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...
Code:
function sendMail($subject, $to, $attachments, $text) {
  $mime_boundary = &quot;<<<--==+X[&quot;.md5(time()).&quot;]&quot;;
  $headers .= &quot;From: Self Evaluation Form\r\n&quot;;
  $headers .= &quot;To: <$to>\r\n&quot;;
  
  $headers .= &quot;MIME-Version: 1.0\r\n&quot;;
  $headers .= &quot;Content-Type: multipart/mixed;\r\n&quot;;
  $headers .= ' boundary=&quot;'.$mime_boundary.'&quot;';
  
  $body = &quot;--&quot;.$mime_boundary.&quot;\r\n&quot;;
  $body .= 'Content_Type: text/plain; charset=&quot;us-ascii&quot;'.&quot;\r\n&quot;;
  $body .= 'Content-Transfer-Encoding: 7bit'.&quot;\r\n&quot;;
  $body .= &quot;$text\r\n&quot;;

  if (is_array($attachments)) {
    foreach($attachments as $filename=>$attachment) {
      $body .= &quot;--&quot;.$mime_boundary.&quot;\r\n&quot;;
      $body .= &quot;Content-Type: application/octet-stream;\r\n&quot;;
      $body .= ' name=&quot;'.$filename.'&quot;'.&quot;\r\n&quot;;
      $body .= &quot;Content-Transfer-Encoding: quoted-printable\r\n&quot;;
      $body .= &quot;Content-Disposition: attachment;\r\n&quot;;
      $body .= ' filename=&quot;'.$filename.'&quot;'.&quot;\r\n&quot;;
      $body .= &quot;\r\n&quot;;
      $body .= $attachment;
      $body .= &quot;\r\n&quot;;
      $body .= &quot;--&quot;.$mime_boundary.&quot;\r\n&quot;;
    }
    echo '<pre>';
    print_r($body);
    $ok = mail($to, $subject, $body, $headers);
  }
}
Called with...
Code:
$attachments['test1.txt']=&quot;Woo hoo moo foo&quot;;
$body = &quot;\r\nTesting 1 2 3&quot;;

sendMail(&quot;Testing this attachment stuffs&quot;, &quot;youremail@here.com&quot;, $attachments, $body);
 
I've seen email attachments with similar names before. And those emails were created using mail clients.

To what mail service are you sending the email?

Have you also tried the same thing using the PHPMailer class? (
Want the best answers? Ask the best questions: TANSTAAFL!!
 
I'm not at work right now and I set the thing up so many months ago I don't even remember... I'm 90% certain it's going through an Exchange server though... so that would explain it.

And no, I haven't bothered with phpmailer yet, I keep seeing it recommended, but haven't had any trouble just writing what I need as of yet... have you found it beneficial?

-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top