public function saveFiles($fileArray)
{
if (empty($fileArray)) {
return array();
}
// Init connection
$this->initConnection();
$savedFiles = array();
@ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
@ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
$charset = "utf-8";
#$charset = "iso-8859-1";
$mail = new Zend_Mail($charset);
$setReturnPath = Mage::getStoreConfig('system/smtp/set_return_path');
switch ($setReturnPath) {
case 1:
$returnPathEmail = $this->getDestination()->getEmailSender();
break;
case 2:
$returnPathEmail = Mage::getStoreConfig('system/smtp/return_path_email');
break;
default:
$returnPathEmail = null;
break;
}
if ($returnPathEmail !== null) {
$mailTransport = new Zend_Mail_Transport_Sendmail("-f" . $returnPathEmail);
Zend_Mail::setDefaultTransport($mailTransport);
}
$mail->setFrom($this->getDestination()->getEmailSender(), $this->getDestination()->getEmailSender());
foreach (explode(",", $this->getDestination()->getEmailRecipient()) as $email) {
if ($charset === "utf-8") {
$mail->addTo($email, '=?utf-8?B?' . base64_encode($email) . '?=');
} else {
$mail->addTo($email, $email);
}
}
foreach ($fileArray as $filename => $data) {
if ($this->getDestination()->getEmailAttachFiles()) {
$attachment = $mail->createAttachment($data);
$attachment->filename = $filename;
}
$savedFiles[] = $filename;
}
#$mail->setSubject($this->_replaceVariables($this->getDestination()->getEmailSubject(), $firstFileContent));
if ($charset === "utf-8") {
$mail->setSubject('=?utf-8?B?' . base64_encode($this->_replaceVariables($this->getDestination()->getEmailSubject(), implode("\n\n", $fileArray))) . '?=');
} else {
$mail->setSubject($this->_replaceVariables($this->getDestination()->getEmailSubject(), implode("\n\n", $fileArray)));
}
$mail->setBodyText(strip_tags($this->_replaceVariables($this->getDestination()->getEmailBody(), implode("\n\n", $fileArray))));
$mail->setBodyHtml($this->_replaceVariables($this->getDestination()->getEmailBody(), implode("\n\n", $fileArray)));
try {
$mail->send(Mage::helper('xtcore/utils')->getEmailTransport());
} catch (Exception $e) {
$this->getTestResult()->setSuccess(false)->setMessage(Mage::helper('xtento_orderexport')->__('Error while sending email: %s', $e->getMessage()));
return false;
}
return $savedFiles;
}