Just nu i M3-nätverket
Jump to content

Bifoga pdf-fil med mail()


laptop14

Recommended Posts

Har problem med att mail() inte skickar med bifogad pdf-fil när jag kör skriptet på servern.

 

Min kod ser ut så här:

 

    <?php

   $to = "min-epost@min-epost.se";

   $from = "min-epost@min-epost.se";

   $subject = "Here is your attachment";

   $fileatt = "fil.pdf";

   $fileatttype = "application/pdf";

   $fileattname = "fil.pdf";

   $headers = "From: $from";

   ?>


   <?php

   $file = fopen( $fileatt, ‘rb’ );

   $data = fread( $file, filesize( $fileatt ) );

   fclose( $file );

   ?>

   <?php

   $semi_rand = md5( time() );

   $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

   $headers .= "\nMIME-Version: 1.0\n" .

   "Content-Type: application/pdf;\n" .

   " boundary='{$mime_boundary}'";

   $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" .

   $message . "\n\n";

   $data = chunk_split( base64_encode( $data ) );

   $message .= "–{$mime_boundary}\n" .

   "Content-Type: {$fileatttype};\n" .

   " name=\"{$fileattname}\"\n" .

   "Content-Disposition: attachment;\n" .

   " filename=\"{$fileattname}\"\n" .

   "Content-Transfer-Encoding: base64\n\n" .

   $data . "\n\n" .

   "–{$mime_boundary}–\n";

   ?>

   <?php

   if( mail( $to, $subject, $message, $headers ) ) {

   echo "<p>The email was sent.</p>";

   }

   else {

   echo "<p>There was an error sending the mail.</p>";

   }

   //}

   ?>

 

Och källkoden i min e-postklient ser ut så här:

 

To: min-epost@min-epost.se
Subject: Here is your attachment
X-PHP-Script: min-domän.se/sendemail.php for [iP-adress ska vara här...]
From: min-epost@min-epost.se
MIME-Version: 1.0
Content-Type: application/pdf;
boundary='==Multipart_Boundary_x86ffe4e4e901026c18fe9e854282eda6x'
Message-Id: <20090823195748.885B42681F@min-epost.se>
Date: Sun, 23 Aug 2009 21:57:48 +0200 (CEST)

This is a multi-part message in MIME format.

–==Multipart_Boundary_x86ffe4e4e901026c18fe9e854282eda6x
Content-Type: text/plain; charset="iso-8859-1
"Content-Transfer-Encoding: 7bit



–==Multipart_Boundary_x86ffe4e4e901026c18fe9e854282eda6x
Content-Type: application/pdf;
name="fil.pdf"
Content-Disposition: attachment;
filename="fil.pdf"
Content-Transfer-Encoding: base64




–==Multipart_Boundary_x86ffe4e4e901026c18fe9e854282eda6x–

 

Min epostklient tar emot bifogade filen som en pdf-fil men den innehåller ingen data? adobe reader kan alltså inte läsa filen. Jag har placerat pdf-filen i samma katalog på servern com skriptet körs i.

 

Verkar som att den inte läser in pdf-filen riktigt i skriptet? Jag har testat med 777 i katalogen på servern.

 

Någon som har tips på lösning?

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...