Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use TCPDF with PHP mail function
    primarykey
    data
    text
    <pre><code>$to = 'my@email.ca'; $subject = 'Receipt'; $repEmail = 'rep@sales.ca'; $fileName = 'receipt.pdf'; $fileatt = $pdf-&gt;Output($fileName, 'E'); $attachment = chunk_split($fileatt); $eol = PHP_EOL; $separator = md5(time()); $headers = 'From: Sender &lt;'.$repEmail.'&gt;'.$eol; $headers .= 'MIME-Version: 1.0' .$eol; $headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\""; $message = "--".$separator.$eol; $message .= "Content-Transfer-Encoding: 7bit".$eol.$eol; $message .= "This is a MIME encoded message.".$eol; $message .= "--".$separator.$eol; $message .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol; $message .= "Content-Transfer-Encoding: 8bit".$eol.$eol; $message .= "--".$separator.$eol; $message .= "Content-Type: application/pdf; name=\"".$fileName."\"".$eol; $message .= "Content-Transfer-Encoding: base64".$eol; $message .= "Content-Disposition: attachment".$eol.$eol; $message .= $attachment.$eol; $message .= "--".$separator."--"; if (mail($to, $subject, $message, $headers)){ $action = 'action=Receipt%20Sent'; header('Location: ../index.php?'.$action); } else { $action = 'action=Send%20Failed'; header('Location: ../index.php?'.$action); } </code></pre> <p>I have been using TCPDF for a short amount of time now to generate PDF files from forms. It works quite well and that part of the PHP has not changed. Now I want to send those PDF files to my email account.</p> <p>The emailing is actually working with this coding and attaching a PDF. The issue is that it is simply a blank PDF at rough 100 bytes in size. Which of course is not a valid PDF nor does it have anything to do with the responses from the form.</p> <p>I am really not familiar with the attaching of files to an email in PHP and any help resolving this issue would be greatly appreciated.</p> <p><strong>Update</strong></p> <p>Since it seems like several people are looking at this still I will post my current solution. It involves downloading PHPMailer as suggested below. I have started at the output line for TCPDF.</p> <pre><code>$attachment = $makepdf-&gt;Output('filename.pdf', 'S'); SENDmail($attachment); function SENDmail($pdf) { require_once('phpmailer/class.phpmailer.php'); $mailer = new PHPMailer(); $mailer-&gt;AddReplyTo('reply@to.ca', 'Reply To'); $mailer-&gt;SetFrom('sent@from.ca', 'Sent From'); $mailer-&gt;AddReplyTo('reply@to.ca', 'Reply To'); $mailer-&gt;AddAddress('send@to.ca', 'Send To'); $mailer-&gt;Subject = 'Message with PDF'; $mailer-&gt;AltBody = "To view the message, please use an HTML compatible email viewer"; $mailer-&gt;MsgHTML('&lt;p&gt;Message contents&lt;/p&gt;')); if ($pdf) {$mailer-&gt;AddStringAttachment($pdf, 'filename.pdf');} $mailer-&gt;Send(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload