---
title: "Bifoga filer mer mail()"
type: "forum-thread"
url: "https://www.webforum.nu/amne/php/129079-bifoga-filer-mer-mail"
topic: "PHP"
topic_url: "https://www.webforum.nu/amne/php"
author: "filipbh"
published: "2005-05-30T07:21:37.000Z"
updated: "2005-06-08T17:59:47.000Z"
replies: 8
views: 381
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/php/129079-bifoga-filer-mer-mail"
---

# Bifoga filer mer mail()

## #1 — filipbh, 2005-05-30T07:21Z

Hej... Är det möjligt att bifoga filer när man använder mailskriptet mail()?

Tack på förhand

Permalänk: https://www.webforum.nu/p/129079

## #2 — sl0k, 2005-05-30T15:05Z

Ja det är det 

<http://se.php.net/manual/en/ref.mail.php>

Permalänk: https://www.webforum.nu/p/1621891

## #3 — filipbh, 2005-05-30T19:12Z

Om du är bra på engelska får du gärna tyda det där lite så jag vet vilken kodsnutt som ska användas m.m.... Tack iaf hittills

Permalänk: https://www.webforum.nu/p/1621989

## #4 — nkrantz, 2005-05-30T19:37Z

> **php.net skrev:**
>
> ```php
> How to add multiple attachment to an email:
> 
> An email can be split into many parts separated by a boundary followed by a Content-Type and a Content-Disposition.
> 
> The boundary is initialized as follows:
> <?php
> $boundary = '-----=' . md5( uniqid ( rand() ) );
> ?>
> 
> You can attach a Word document if you specify:
> <?php
> $message .= "Content-Type: application/msword; name=\"my attachment\"\n";
> $message .= "Content-Transfer-Encoding: base64\n";
> $message .= "Content-Disposition: attachment; filename=\"$theFile\"\n\n";
> ?>
> 
> When adding a file you must open it and read it with fopen and add the content to the message:
> <?php
> $path = "whatever the path to the file is";
> $fp = fopen($path, 'r');
> do //we loop until there is no data left
> {
>        $data = fread($fp, 8192);
>        if (strlen($data) == 0) break;
>        $content .= $data;
>      } while (true);
> $content_encode = chunk_split(base64_encode($content));
> $message .= $content_encode . "\n";
> $message .= "--" . $boundary . "\n";
> ?>
> 
> Add the needed headers and send!
> <?php
> $headers  = "From: \"Me\"<me@here.com>\n";
> $headers .= "MIME-Version: 1.0\n";
> $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";
> mail('myAddress@hotmail.com', 'Email with attachment from PHP', $message, $headers);
> ?>
> 
> Finally, if you add an image and want it displayed in your email, change the Content-Type from attachment to inline:
> 
> <?php
> $message .= "Content-Disposition: inline; filename=\"$theFile\"\n\n";
> ?>
> 
> Enjoy!
> ```

Permalänk: https://www.webforum.nu/p/1622002

## #5 — filipbh, 2005-05-30T22:22Z

Jag får inte med filen... 

Måste man ändra "msword" i $message .= "Content-Type: application/msword; name=\\"my attachment\\"\\n"; till nåt annat om det inte är en word-fil?

Permalänk: https://www.webforum.nu/p/1622113

## #6 — filipbh, 2005-05-30T22:57Z

Om jag får med nån fil så står det untitled och 0 k... Det är framför allt pdf-filer som ska skickas. Men jag vill kunna använda skriptet till mer än det.

Permalänk: https://www.webforum.nu/p/1622117

## #7 — filipbh, 2005-06-07T22:34Z

Ingen som vet vad jag ska göra och vad felet är?

Permalänk: https://www.webforum.nu/p/1625268

## #8 — dave_jr, 2005-06-08T06:47Z

Jag hade oxå stora problem med att bifoga filer.

De jag frågade hävdade att min kod var korrekt och jag testade då istället att lägga upp koden på ett annat webhotell - och vips - det fungerade! Olika hotell har olika begränsningar - har du möjligheten så testa någon annanstans oxå.

Permalänk: https://www.webforum.nu/p/1625306

## #9 — filipbh, 2005-06-08T17:59Z

Egentligen inte.. Men jag får väl fixa ett. Vilken inställning ska man ha för att det ska gå då? Vilket hade du som inte fungerade? B-one eller? De använder jag nu...

Permalänk: https://www.webforum.nu/p/1628540

---

Tråden på webben: https://www.webforum.nu/amne/php/129079-bifoga-filer-mer-mail
