php - 如何将 csv 文件附加到 php 电子邮件(从 magento root 运行的代码)

标签 php magento csv smtp sendmail

我在 magento 根目录中有以下代码来发送电子邮件。

<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app("default");

$body = "Hi there, here is some body content";
$mail = Mage::getModel('core/email');
$mail->setToName('John');
$mail->setToEmail('ab@example.net');
$mail->setBody($body);
$mail->setSubject('The Subject');
$mail->setFromEmail('yourstore@url.com');
$mail->setFromName("Your Name");
$mail->setType('text');// You can use 'html' or 'text'

try {
    $mail->send();
    Mage::getSingleton('core/session')->addSuccess('Your request has been sent');

}
catch (Exception $e) {
    Mage::getSingleton('core/session')->addError('Unable to send.');

}

?>

如何在这封电子邮件中附加多个 csv 文件。(至少 3 或 4 个)。

最佳答案

你可以使用 zend 并且这个代码已经过测试

require 'app/Mage.php';
umask( 0 );
Mage :: app( "default" );
$mail = new Zend_Mail();
$mail->setType(Zend_Mime::MULTIPART_RELATED);
$mail->setBodyHtml($html_body);
$mail->setFrom('support@example.com', 'Example');
$mail->addTo('dev.amitbera@gmail.com', 'Amit');
$mail->setSubject('Sending email using Zend Framework');
$dir = Mage::getBaseDir();
$path = $dir.DS.'var'.DS.'docs'.DS.'test.csv';
$file = $mail->createAttachment(file_get_contents($path));
$file ->type        = 'text/csv';
$file ->disposition = Zend_Mime::DISPOSITION_INLINE;
$file ->encoding    = Zend_Mime::ENCODING_BASE64;
$file ->filename    = 'test.csv';
$mail->send();

关于php - 如何将 csv 文件附加到 php 电子邮件(从 magento root 运行的代码),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20904249/

相关文章:

php - 使用 mysql_query() 获取位字段

php - 有条件地删除 Magento 中的页眉/页脚

python - 将多个 csv 文件合并到 pandas 时在列中添加文件名 - Python

ruby - 使用ruby操作.csv文件 : Multiplying two columns together

python - 如何使用 python 和 pandas 将单个 `"` 放入我的 csv 中

php - PDO 连接字符串 : What is the best way to do it?

php - codeigniter 如何清理输入?

Magento 1.6.2 - 覆盖联系人 Controller 的问题

xml - 如何从产品页面中删除 'tags' block ?

php - 数据库更新 - 找不到列 laravel