I want to send generated PDF in a mail attachment.
I am able to download it locally but I want to email the PDF without even downloading.
I found some help on this thread. But it only shows the message, not the attachment.
I want to send generated PDF in a mail attachment.
I am able to download it locally but I want to email the PDF without even downloading.
I found some help on this thread. But it only shows the message, not the attachment.
Why not use PHPMailer?
Download their repo here, extract the archive and copy the script's folder to your project. Include the main script file with
require_once('path/to/file/class.phpmailer.php');
Now, sending emails with attachments goes from being insanely difficult to incredibly easy:
$email = new PHPMailer();
$email->From = 'you@example.com';
$email->FromName = 'Your Name';
$email->Subject = 'Message Subject';
$email->Body = $bodytext;
$email->AddAddress( 'destinationaddress@example.com' );
$file_to_attach = 'PATH_OF_YOUR_FILE_HERE';
$email->AddAttachment( $file_to_attach , 'NameOfFile.pdf' );
return $email->Send();
It's just that one line $email->AddAttachment();
, you couldn't ask for any easier.
If you do it with PHP's mail()
function, you'll be writing stacks of code, and you'll probably have lots of really difficult to find bugs.