2
我有一个通过电子邮件发送给店主的表单。没有什么奇特的,只是一堆输入字段和选择字段。Magento用CSV发送信息
我试图把它变成一个附加到电子邮件的CSV文件。
在我的控制,我有:
public function postAction() {
$post = $this->getRequest()->getPost();
if ($post) {
#Mage::log($post,null,'tmp.log');
#not using this at the moment...
$postObject = new Varien_Object();
$postObject->setData($post);
$file = fopen('temp/temp.csv','w+');
foreach($post as $sections) {
fputcsv($file, $sections);
};
fclose($file);
$mailTemplate = Mage::getModel('core/email_template')->loadDefault('training_email_template');
$mailTemplate->setSenderName('Joe Schmoe');
$mailTemplate->setSenderEmail('[email protected]');
$mailTemplate->setTemplateSubject('Form Submission');
$attachment = $mailTemplate->getMail()->createAttachment($file);
$attachment->filename = 'file.csv';
$mailTemplate->send(
'[email protected]',
Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
$post
);
}
}
现在文件本身被创建,我可以打开temp.csv就好了,它看起来像它应该。然而,正在附加的文件是空的,或者(当我尝试了其他一些事情时),编码将会全部不合格......显然不是正确的格式。
感觉我只是想念一些简单的东西......任何人都有一些建议?
的文档......我今天失败的谷歌。谢谢! – pspahn