Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Problema Invio PDF via mail() al volo

    Ho recuperato un piccolo script da internet che dovrebbe inviare al volo un file PDF generato con FPDF il codice è questo:

    Codice PHP:
    define('FPDF_FONTPATH','../../utils/fpdf/font/');
    require(
    '../../utils/fpdf/fpdf.php');

    $pdf = new FPDF();
    $pdf->AddPage();
    $pdf->SetFont("Arial","B",14);
    $pdf->Cell(40,10"this is a pdf example");

    $to "test@myown.it"
    $from "noreply@myown.it"
    $subject "send email with pdf attachment"
    $message "

    Please see the attachment.</p>"
    ;

    $separator md5(time());
    $eol PHP_EOL;
    $filename "example.pdf";
    $pdfdoc $pdf->Output("""S");

    $attachment chunk_split(base64_encode($pdfdoc));

    $headers  "From: ".$from.$eol;
    $headers .= "MIME-Version: 1.0".$eol
    $headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol
    $headers .= "Content-Transfer-Encoding: 7bit".$eol;
    $headers .= "This is a MIME encoded message.".$eol.$eol;
    $headers .= "--".$separator.$eol;
    $headers .= "Content-Type: application/pdf; name=\"".$filename."\"".$eol
    $headers .= "Content-Transfer-Encoding: base64".$eol;
    $headers .= "Content-Disposition: attachment".$eol.$eol;
    $headers .= $attachment.$eol.$eol;
    $headers .= "--".$separator."--";

    mail($to$subject$message$headers); 
    Il problema è che il risultato arriva si allegato alla mail ma è troncato della testa come potete vedere in questo screenshot:



    Secondo voi come posso correggere questa problematica?

    Grazie 1000.
    Se tu dai una moneta e me e io una a te avremo una moneta ciascuno, ma se io do uno script a te e tu uno a me, avremo due script ciascuno.
    Maledetto script di configurazione! - And therefore the scythe cuts down its victims…

  2. #2
    Risolto con questo script:

    Codice PHP:
    <?
    define
    ('FPDF_FONTPATH','../../utils/fpdf/font/');
    require(
    '../../utils/fpdf/fpdf.php');

    $pdf = new FPDF();
    $pdf->AddPage();
    $pdf->SetFont("Arial","B",14);
    $pdf->Cell(40,10"this is a pdf example");

    $from "ciupa@myown.com"
    $subject "send email with pdf attachment"
    $message "Please see the attachment.";

    $separator md5(time());
    $eol PHP_EOL;
    $filename "example.pdf";
    $pdfdoc $pdf->Output("example.pdf""F");

    $to "me@myown.com"
    $subject 'Test email with attachment';
    $random_hash md5(date('r'time()));
    $headers "From: [email]webmaster@example.com[/email]\r\nReply-To: $to";
    $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
    $attachment chunk_split(base64_encode(file_get_contents('example.pdf')));

    ob_start(); 
    ?>
    --PHP-mixed-<?php echo $random_hash?> 
    Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash?>"

    --PHP-alt-<?php echo $random_hash?> 
    Content-Type: text/plain; charset="iso-8859-1"
    Content-Transfer-Encoding: 7bit

    Hello World!!!
    This is simple text email message.

    --PHP-alt-<?php echo $random_hash?> 
    Content-Type: text/html; charset="iso-8859-1"
    Content-Transfer-Encoding: 7bit

    <h2>Hello World!</h2>


    This is something with [b]HTML[/b] formatting.</p>

    --PHP-alt-<?php echo $random_hash?>--

    --PHP-mixed-<?php echo $random_hash?> 
    Content-Type: application/pdf; name="example.pdf" 
    Content-Transfer-Encoding: base64 
    Content-Disposition: attachment 

    <?php echo $attachment?>
    --PHP-mixed-<?php echo $random_hash?>--

    <?php
    $message 
    ob_get_clean();
    $mail_sent = @mail$to$subject$message$headers );
    echo 
    $mail_sent "Mail sent" "Mail failed";
    ?>
    Tutti gli altri tipi di codice creano allegati corrotti...
    Se tu dai una moneta e me e io una a te avremo una moneta ciascuno, ma se io do uno script a te e tu uno a me, avremo due script ciascuno.
    Maledetto script di configurazione! - And therefore the scythe cuts down its victims…

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.