2017-03-09 2 views
0

Das ist, was ich bin versuchtWie eine Excel-Anlage in QCubed senden

$attach ist der Weg zu meinem Excel => c: /xampp/htdocs/project/excel.xlsx

Notification::SendEmail('[email protected]', '[email protected]', "Subject","message", $attach); 

Wenn die $attach entfernt wird, wird die E-Mail gehen. aber es funktioniert nicht, wenn ich die Befestigung

Sendemail-Funktion

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; 
} 

Antwort

0

Ich habe die Antwort für diese Erweiterung, Verwendung dieser Code:

$Attachment = $file_path; // path to your excel 
Notification::SendEmail('[email protected]',[email protected],com, "Subject", "Message", $Attachment); 

in 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; 
} 

Das wird die Arbeit machen.

Verwandte Themen