• hi all!

    I’m working on a custom form that when I click send, it should pick up some fields in this form, generate a PDF and send by email.
    And for this I’m using the FPDF class that ultimately allows me to generate the pdf file and puts it into a string. But when I try to send this string with all the headers, the file arrives attached to the name “noname.pdf.” And when I send email through the path of a file that is on disk, the file usually arrives, but I did not want to save the file on disk but only work with memory.

    Could anyone help me?

    Below is my code, thanks!

    <?php
    include("wp-blog-header.php");
    get_header();
    
    $largura = $_POST['largura'];
    
    require('fpdf/fpdf.php');
    define('FPDF_FONTPATH', 'fpdf/font');
    $pdf = new FPDF();
    $pdf->open();
    $pdf->AddPage();
    $pdf->SetFont('helvetica', '', 10);
    $pdf->SetMargins(0, 0, 0);
    $pdf->SetY("2.25");
    $pdf->SetX("11.6");
    $pdf->Cell(100, 10, $largura);
    $pdfdoc = $pdf->Output("", "S");
    
    $separador = md5(time());
    
    $attachment = chunk_split(base64_encode($pdfdoc));
    $from = "gleite@azclick.com.br";
    $subject = "Email de teste";
    $message = "Este é o corpo da mensagem.";
    
    $nomeArquivo = 'teste.pdf';
    
    $headers  = "From: ".$from."\r\n";
    $headers .= "MIME-Version: 1.0"."\r\n";
    $headers .= "Content-Type: multipart/mixed; boundary=\"".$separador."\"";
    $headers .= "Content-Transfer-Encoding: 8bit"."\r\n";
    $headers .= "This is a MIME encoded message."."\r\n";
    $headers .= "Content-Type: application/octet-stream name=\"".$nomeArquivo."\"";
    $headers .= "Content-Transfer-Encoding: base64";
    $headers .= "Content-Disposition: attachment; filename=\"".$nomeArquivo."\"";
    
    $envio = wp_mail($to, $subject, $message, $headers, $attachment);
    if($envio){
    	$result = 'E-mail enviado com sucesso.';
    } else{
    	$result = 'Ocorreu um erro ao enviar seu orçamento.';
    }
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter gabrieldepaula

    (@gabrieldepaula)

    anybody?

    I have not tested this but at a glance.

    You can add a name here:

    $pdf->Output(“NAME HERE”, “S”);

    Secondly I believe the attachment has to be an array:

    $attachment = array(chunk_split(base64_encode($pdfdoc)));

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Send a PDF attachment generated by fpdf using wp_mail’ is closed to new replies.