我有一个包含以下字段的表单。
此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();
我得到了这个例外
无法打开文件进行阅读 [/user_upload/Jobs_1525757243_sample.pdf]
所以我已经取代了这个
$attachment = Swift_Attachment::newInstance($folder->getIdentifier().$pdfFinalName, 'Document.pdf', 'application/pdf');
$mail->attach($attachment);
两者都不起作用,哪里出错了?
答案 0 :(得分:0)
使用ext:powermail,它功能丰富,主动维护且记录良好
答案 1 :(得分:0)
对我有用的是在标识符前面添加fileadmin
$filePath = 'fileadmin' . $file->getOriginalResource()->getIdentifier();
$attachment = \Swift_Attachment::fromPath($filePath);
$mail->attach($attachment);