Search code examples
pdfbinarymime-typesemail-attachmentshidden-field

how to attach pdf binary which is assigned in hidden field and send it to email


After submit the pdf binary is saved to the hidden field pdfStream how to use php to get the value from the hidden field and send it to email as pdf file

<input type="hidden" id="pdfStream" name="pdfStream" value="<?php echo $var; ?>" />

email.php

    <?php
    require('phpmailer/class.phpmailer.php');
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->SMTPDebug = 0;
    $mail->SMTPAuth = TRUE;
    $mail->SMTPSecure = "tls";
    $mail->Port     = 25;  
    $mail->Username = "@hotmail.com";
    $mail->Password = "********";
    $mail->Host     = "smtp.live.com";
    $mail->Mailer   = "smtp";
    $mail->AddAddress("@gmail.com");    
    $mail->Subject = $_POST["subject"];
    $mail->WordWrap   = 80;
    $mail->MsgHTML($_POST["content"]);

    $attachdata = $_GET['pdfStream'];
   $mail->AddAttachment($attachdata,'ApplicationHistory','base64','application/pdf');
    }

     $mail->IsHTML(true);

    if(!$mail->Send()) {
     echo "<p class='error'>Problem in Sending Mail.</p>";
    } else {
    echo "<p class='success'>Contact Mail Sent.</p>";
    }   
    ?>

After submit i'm getting the pdf file but no contents on it(blank)


Solution

  • Are you passing hidden value via GET? try using $_POST['pdfStream'] instead of $_GET['pdfStream']