如何在 QCubed 中发送 excel 附件
How to send a excel attachment in QCubed
这就是我正在尝试的
$attach
是我的 excel => c:/xampp/htdocs/project/excel.xlsx
的路径
Notification::SendEmail('xyz@gmail.com', 'abc@gmail.com', "Subject","message", $attach);
如果 $attach
被删除,那么电子邮件将会消失。
但是如果我添加附件就失败了
发送电子邮件函数
public static function SendEmail($mixFrom, $mixTo, $strSubject, $strMessage, $mixAttachment = null, $mixCc = null, $mixBcc = null) {
// Declaration of Local Variables
$strSMTPHost = QApplication::getSettingValue(Mssetting::SMTP_HOST);
$strSMTPPort = QApplication::getSettingValue(Mssetting::SMTP_PORT);
$objMessage = Swift_Message::newInstance($strSubject, $strMessage, 'text/html');
// Set the source/destination data
$objMessage->setFrom($mixFrom);
$objMessage->setTo($mixTo);
$objMessage->setCc($mixCc);
$objMessage->setBcc($mixBcc);
// Check for attachments
if(is_array($mixAttachment)) {
foreach($mixAttachment as $strFilePath)
$objMessage->attach (Swift_Attachment::fromPath ($strFilePath));
}
elseif(is_string($mixAttachment)) {
$objMessage->attach(Swift_Attachment::fromPath($mixAttachment));
}
// Setup the transport
$objTransport = Swift_SmtpTransport::newInstance();
if($strSMTPHost) $objTransport->setHost ($strSMTPHost);
if($strSMTPPort) $objTransport->setPort($strSMTPPort);
// Setup the mailer
$objMailer = Swift_Mailer::newInstance($objTransport);
// Send the message
$objMailer->send($objMessage, $arrFailures);
if($arrFailures)
return $arrFailures;
return true;
}
我得到了答案,
使用此代码:
$Attachment = $file_path; // path to your excel
Notification::SendEmail('from@abc.com',to@abc,com, "Subject", "Message", $Attachment);
在Notification.php
class Notification {
public static function SendEmail($mixFrom, $mixTo, $strSubject, $strMessage, $mixAttachment, $mixCc = null, $mixBcc = null) {
// Declaration of Local Variables
$strSMTPHost = QApplication::getSettingValue(Mssetting::SMTP_HOST);
$strSMTPPort = QApplication::getSettingValue(Mssetting::SMTP_PORT);
$objMessage = Swift_Message::newInstance($strSubject, $strMessage, 'text/html');
// Set the source/destination data
$objMessage->setFrom($mixFrom);
$objMessage->setTo($mixTo);
$objMessage->setCc($mixCc);
$objMessage->setBcc($mixBcc);
// Check for attachments
if(is_array($mixAttachment)) {
foreach($mixAttachment as $strFilePath)
$objMessage->attach (Swift_Attachment::fromPath ($strFilePath));
}
elseif(is_string($mixAttachment)) {
$objMessage->attach(Swift_Attachment::fromPath($mixAttachment));
}
// Setup the transport
$objTransport = Swift_SmtpTransport::newInstance();
if($strSMTPHost) $objTransport->setHost ($strSMTPHost);
if($strSMTPPort) $objTransport->setPort($strSMTPPort);
// Setup the mailer
$objMailer = Swift_Mailer::newInstance($objTransport);
// Send the message
$objMailer->send($objMessage, $arrFailures);
if($arrFailures)
return $arrFailures;
return true;
}
这将完成工作。
这就是我正在尝试的
$attach
是我的 excel => c:/xampp/htdocs/project/excel.xlsx
Notification::SendEmail('xyz@gmail.com', 'abc@gmail.com', "Subject","message", $attach);
如果 $attach
被删除,那么电子邮件将会消失。
但是如果我添加附件就失败了
发送电子邮件函数
public static function SendEmail($mixFrom, $mixTo, $strSubject, $strMessage, $mixAttachment = null, $mixCc = null, $mixBcc = null) {
// Declaration of Local Variables
$strSMTPHost = QApplication::getSettingValue(Mssetting::SMTP_HOST);
$strSMTPPort = QApplication::getSettingValue(Mssetting::SMTP_PORT);
$objMessage = Swift_Message::newInstance($strSubject, $strMessage, 'text/html');
// Set the source/destination data
$objMessage->setFrom($mixFrom);
$objMessage->setTo($mixTo);
$objMessage->setCc($mixCc);
$objMessage->setBcc($mixBcc);
// Check for attachments
if(is_array($mixAttachment)) {
foreach($mixAttachment as $strFilePath)
$objMessage->attach (Swift_Attachment::fromPath ($strFilePath));
}
elseif(is_string($mixAttachment)) {
$objMessage->attach(Swift_Attachment::fromPath($mixAttachment));
}
// Setup the transport
$objTransport = Swift_SmtpTransport::newInstance();
if($strSMTPHost) $objTransport->setHost ($strSMTPHost);
if($strSMTPPort) $objTransport->setPort($strSMTPPort);
// Setup the mailer
$objMailer = Swift_Mailer::newInstance($objTransport);
// Send the message
$objMailer->send($objMessage, $arrFailures);
if($arrFailures)
return $arrFailures;
return true;
}
我得到了答案, 使用此代码:
$Attachment = $file_path; // path to your excel
Notification::SendEmail('from@abc.com',to@abc,com, "Subject", "Message", $Attachment);
在Notification.php
class Notification {
public static function SendEmail($mixFrom, $mixTo, $strSubject, $strMessage, $mixAttachment, $mixCc = null, $mixBcc = null) {
// Declaration of Local Variables
$strSMTPHost = QApplication::getSettingValue(Mssetting::SMTP_HOST);
$strSMTPPort = QApplication::getSettingValue(Mssetting::SMTP_PORT);
$objMessage = Swift_Message::newInstance($strSubject, $strMessage, 'text/html');
// Set the source/destination data
$objMessage->setFrom($mixFrom);
$objMessage->setTo($mixTo);
$objMessage->setCc($mixCc);
$objMessage->setBcc($mixBcc);
// Check for attachments
if(is_array($mixAttachment)) {
foreach($mixAttachment as $strFilePath)
$objMessage->attach (Swift_Attachment::fromPath ($strFilePath));
}
elseif(is_string($mixAttachment)) {
$objMessage->attach(Swift_Attachment::fromPath($mixAttachment));
}
// Setup the transport
$objTransport = Swift_SmtpTransport::newInstance();
if($strSMTPHost) $objTransport->setHost ($strSMTPHost);
if($strSMTPPort) $objTransport->setPort($strSMTPPort);
// Setup the mailer
$objMailer = Swift_Mailer::newInstance($objTransport);
// Send the message
$objMailer->send($objMessage, $arrFailures);
if($arrFailures)
return $arrFailures;
return true;
}
这将完成工作。