PHP Email attachment on open not correctly decoded? -


i made 2 scripts 1 script did needed done. ain't. somehow email attachment part not working how should , have tried numerous changes can't work.

the problem

in mailbox recipient receives following attachment (filename.pdf.pdf .dat) , should filename.pdf

i added below script using , html form. both pages add code has attachment keep question more clear.

this part of send.php:

    <form action="send_script.php" method="post" name="form1" id="form1" enctype="multipart/form-data">     <div><input type="file" name="fileattach" value="zoeken"></div>     <div><input type="submit" name="submit" value="verzenden"></div>     </form> 

this part of send_script.php:

if($_files["fileattach"]["name"] != "") {     $strfilesname = $_files["fileattach"]["name"];     $strcontent = chunk_split(base64_encode(file_get_contents($_files["fileattach"]["tmp_name"])));  }      ob_start(); //turn on output buffering      --php-mixed-<?php echo $random_hash; ?>       content-type: application/octet-stream; name="<?php echo $strfilesname?>"       content-transfer-encoding: base64       content-disposition: attachment; filename="<?php echo $strfilesname?>"      <?php echo $strcontent; ?>      $message = ob_get_clean();      $mail_sent = @mail( $to, $subject, $message, $headers );      echo $mail_sent ? "mail sent" : "mail failed";      ?> 

edit 1 above code changed of below comments helping me far. file correctly showing op test.pdf , name test. perfect. problem cant opened gives following error.

error adobe acrobat: sent email attachment , not correctly decoded!

edit 2 gave on above code , set on change following gets dynamic name , works on pdf.

   $attachment = chunk_split(base64_encode(file_get_contents('attachment.zip')));     --php-mixed-<?php echo $random_hash; ?>      content-type: application/zip; name="attachment.zip"      content-transfer-encoding: base64      content-disposition: attachment      <?php echo $attachment; ?>  

i changed far:

    $attachment = chunk_split(base64_encode(file_get_contents($_files["fileattach"]["tmp_name"])));     --php-mixed-<?php echo $random_hash; ?>       content-type: application/octet-stream; name="eenbestand.pdf"       content-transfer-encoding: base64       content-disposition: attachment       <?php echo $attachment; ?>  

the file can received , opens correctly dynamic name!

should content-type header not application/pdf?

(i would've added comment if could, i'm not sure correct/relevant.)


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -