Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I just had to figure this out and my eyeballs were definitely sore by the end...</p> <p>1) You need to install <a href="http://sourceforge.net/projects/phpmailer/" rel="nofollow noreferrer">PHPMailer</a> to the php server.</p> <p>2) Include the PHPmailer class in your TCPDF script, like so (your path may vary):</p> <pre><code>require_once('../PHPMailer_v5.1/class.phpmailer.php'); </code></pre> <p>3) Now after your pdf code simply talk to PHPMailer like so:</p> <pre><code>$filename = "custompdf_$name_$time.pdf"; $pdf-&gt;Output($filename, 'F'); // save the pdf under filename $mail = new PHPMailer(); $mail-&gt;IsSMTP(); $mail-&gt;Host = "mail.yourhost.com"; $mail-&gt;SMTPAuth = true; // enable SMTP authentication $mail-&gt;Port = 26; // set the SMTP port for the GMAIL server $mail-&gt;Username = "user+yourhost.com"; // SMTP account username $mail-&gt;Password = "topsecret"; // SMTP account password $mail-&gt;From = "noreply@yourhost.com"; $mail-&gt;FromName = "Stack Overflower"; $mail-&gt;AddAddress( $email, $name ); // in this case the variable has been passed $mail-&gt;AddCC( "person@somehost.net", "Johnny Person"); // in this case we just hard code it $mail-&gt;SMTPDebug = 0; // use 2 for debugging the email send $pdf_content = file_get_contents($filename); $mail-&gt;WordWrap = 50; $mail-&gt;AddStringAttachment($pdf_content, "custompdf_for_$name_$time.pdf", "base64", "application/pdf"); // note second item is name of emailed pdf $mail-&gt;IsHTML(true); $mail-&gt;Subject = "Your pdf is here"; $mail-&gt;Body = "Dear $name,&lt;br&gt; Here is your custom generated pdf generated at $t.&lt;br&gt;&lt;br&gt; Thank you"; if(!$mail-&gt;Send()) { echo "Sorry ... EMAIL FAILED"; } else { echo "Done. . . Email sent to $email at $t."; } unlink($filename); // this will delete the file off of server </code></pre> <p>Of course you have many options for the email sent, like not using html, or sending both html and text, adding many recipients and/or cc's, etc. </p> <p>EDIT: This does save the file temporarily on the server, but it cleans up after itself with the unlink command.</p>
 

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