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

Muk*_*esh 3 php csv smtp sendmail magento

我在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.');

}

?>
Run Code Online (Sandbox Code Playgroud)

如何使用此电子邮件附加多个csv文件.(至少3或4).

Ami*_*era 7

你可以使用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();
Run Code Online (Sandbox Code Playgroud)