Hello,
I'm trying to avoid having to save a pdf as a new Attachment before sending the pdf as an attachment to the email. Is this possible?
Something like:
I'm trying to avoid having to save a pdf as a new Attachment before sending the pdf as an attachment to the email. Is this possible?
Something like:
PHP Code:
$contents = file_get_contents('/?entryPoint=pdf&entityType={myEntityType}&entityId ={myEntityId}&templateId={myTemplateId}');
$attachmentRepository = $this->recordServiceContainer
->get(Attachment::ENTITY_TYPE)
->getRepository();
$attachment = $attachmentRepository->getNew();
$attachment->setContents($contents);
$attachment->set([
'name' => 'myPdfName',
'type' => 'application/pdf',
]);
$email = $this->emailFactory->create();
$email->setSubject($subject);
$email->setBody($body);
$email->addToAddress({toaddress});
$email->setIsHtml(true);
$email->addAttachment($attachment);
$attachmentList = [$attachment];
$this->emailSender
->withAttachments($attachmentList)
->send($email);
Comment