如何在 TYPO3 中上传 PDF 文件并通过电子邮件发送?
How to upload a PDF file and send via email in TYPO3?
我有一个包含以下字段的表单。
- 姓名
- 地址
- 联系方式
- PDF(文件附件)
此 PDF 将从系统上传,并将这些详细信息与上传的 PDF 一起通过电子邮件发送。我希望这些详细信息位于使用独立视图和发送的自定义电子邮件模板中。
我正在使用 TYPO3 v7.6.23
我是 TYPO3 的新手。怎么做?
我在这里添加我的代码
$addJobsInfo = GeneralUtility::makeInstance('MNU\MnuJobs\Domain\Model\Jobs');
$addJobsInfo->setName($arguments['name']);
$addJobsInfo->setAddress($arguments['address']);
$addJobsInfo->setContact($arguments['contact']);
$this->jobsRepository->add($addJobsInfo);
$persistenceManager = $this->objectManager->get('TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager');
$persistenceManager->persistAll();
$lastID = $addJobsInfo->getUid();
$getPDF = $_FILES;
if(!empty($getPDF)){
$pdfName = $getPDF['tx_mnujobs_mnujobs']['name']['jobsDOC'];
$pdfTemp = $getPDF['tx_mnujobs_mnujobs']['tmp_name']['jobsDOC'];
$resourceFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
$storage = $resourceFactory->getDefaultStorage();
$folder = $storage->getFolder('user_upload');
$pdfFinalName = 'Jobs_'.time().'_'.$pdfName;
$uploadPDF = $storage->addFile($pdfTemp, $folder, $pdfFinalName);
if($lastID){
$newId = 'NEW'.$lastID;
$data = array();
$data['sys_file_reference'][$newId] = array(
'table_local' => 'sys_file',
'uid_local' => $uploadPDF->getUid(),
'tablenames' => 'tx_mnujobs_domain_model_jobs',
'uid_foreign' => $lastID,
'fieldname' => 'pdfattachment',
'pid' => $this->settings['pageUid']
);
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
$dataHandler->start($data, array());
$dataHandler->process_datamap();
}
}
//E-mail Sending
$mail = GeneralUtility::makeInstance('TYPO3\CMS\Core\Mail\MailMessage');
$mail->setSubject('Contact Details');
$mail->setTo('sample@gmail.com']);
$mail->setBody('Hi, This is a sample. Please Find the Attachment', 'text/html');
$attachment = Swift_Attachment::fromPath($folder->getIdentifier().$pdfFinalName);
$attachment->setFilename('Document.pdf');
$mail->attach($attachment);
$sendMail = $mail->send();
我遇到了这个异常
Unable to open file for reading
[/user_upload/Jobs_1525757243_sample.pdf]
所以我已经替换了这个
$attachment = Swift_Attachment::newInstance($folder->getIdentifier().$pdfFinalName, 'Document.pdf', 'application/pdf');
$mail->attach($attachment);
两者都不行,我哪里出错了?
使用 ext:powermail,它功能丰富,维护积极且有据可查
对我有用的是在标识符前面添加 fileadmin
:
$filePath = 'fileadmin' . $file->getOriginalResource()->getIdentifier();
$attachment = \Swift_Attachment::fromPath($filePath);
$mail->attach($attachment);
我有一个包含以下字段的表单。
- 姓名
- 地址
- 联系方式
- PDF(文件附件)
此 PDF 将从系统上传,并将这些详细信息与上传的 PDF 一起通过电子邮件发送。我希望这些详细信息位于使用独立视图和发送的自定义电子邮件模板中。
我正在使用 TYPO3 v7.6.23
我是 TYPO3 的新手。怎么做?
我在这里添加我的代码
$addJobsInfo = GeneralUtility::makeInstance('MNU\MnuJobs\Domain\Model\Jobs');
$addJobsInfo->setName($arguments['name']);
$addJobsInfo->setAddress($arguments['address']);
$addJobsInfo->setContact($arguments['contact']);
$this->jobsRepository->add($addJobsInfo);
$persistenceManager = $this->objectManager->get('TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager');
$persistenceManager->persistAll();
$lastID = $addJobsInfo->getUid();
$getPDF = $_FILES;
if(!empty($getPDF)){
$pdfName = $getPDF['tx_mnujobs_mnujobs']['name']['jobsDOC'];
$pdfTemp = $getPDF['tx_mnujobs_mnujobs']['tmp_name']['jobsDOC'];
$resourceFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
$storage = $resourceFactory->getDefaultStorage();
$folder = $storage->getFolder('user_upload');
$pdfFinalName = 'Jobs_'.time().'_'.$pdfName;
$uploadPDF = $storage->addFile($pdfTemp, $folder, $pdfFinalName);
if($lastID){
$newId = 'NEW'.$lastID;
$data = array();
$data['sys_file_reference'][$newId] = array(
'table_local' => 'sys_file',
'uid_local' => $uploadPDF->getUid(),
'tablenames' => 'tx_mnujobs_domain_model_jobs',
'uid_foreign' => $lastID,
'fieldname' => 'pdfattachment',
'pid' => $this->settings['pageUid']
);
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
$dataHandler->start($data, array());
$dataHandler->process_datamap();
}
}
//E-mail Sending
$mail = GeneralUtility::makeInstance('TYPO3\CMS\Core\Mail\MailMessage');
$mail->setSubject('Contact Details');
$mail->setTo('sample@gmail.com']);
$mail->setBody('Hi, This is a sample. Please Find the Attachment', 'text/html');
$attachment = Swift_Attachment::fromPath($folder->getIdentifier().$pdfFinalName);
$attachment->setFilename('Document.pdf');
$mail->attach($attachment);
$sendMail = $mail->send();
我遇到了这个异常
Unable to open file for reading [/user_upload/Jobs_1525757243_sample.pdf]
所以我已经替换了这个
$attachment = Swift_Attachment::newInstance($folder->getIdentifier().$pdfFinalName, 'Document.pdf', 'application/pdf');
$mail->attach($attachment);
两者都不行,我哪里出错了?
使用 ext:powermail,它功能丰富,维护积极且有据可查
对我有用的是在标识符前面添加 fileadmin
:
$filePath = 'fileadmin' . $file->getOriginalResource()->getIdentifier();
$attachment = \Swift_Attachment::fromPath($filePath);
$mail->attach($attachment);