我在 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/