2016-08-03 31 views
0

Ich versuche, eine Excel-Datei zu erstellen und senden Sie es als E-Mail ohne es auf dem Server zu speichern. E-Mail ist erfolgreich, aber ohne Anhang. Bitte helfenSo erstellen und hängen Excel-Datei mit E-Mail in Mime PHP

<?php 
include 'Mail.php'; 
include 'Mail/mime.php' ; 

//creating excel file 

header('Content-type: application/excel'); 
$t=time(); 
$filename ="rep$t.xls"; 
header('Content-Disposition: attachment; filename='.$filename); 
$data = '<html xmlns:x="urn:schemas-microsoft-com:office:excel"> 
<head> 
<!--[if gte mso 9]> 
<xml> 
    <x:ExcelWorkbook> 
     <x:ExcelWorksheets> 
      <x:ExcelWorksheet> 
       <x:Name>Sheet 1</x:Name> 
       <x:WorksheetOptions> 
        <x:Print> 
         <x:ValidPrinterInfo/> 
        </x:Print> 
       </x:WorksheetOptions> 
      </x:ExcelWorksheet> 
     </x:ExcelWorksheets> 
    </x:ExcelWorkbook> 
</xml> 
<![endif]--> 
</head> 

<body> 
<table><tr> 
<th>SL</th> 
<th>id</th> 
<th>DATE TIME</th> 
<th>Name</th> 
<th>Roll No</th> 
<th>Class</th> 
<th>Section</th> 
<th>FEE</th> 
<th>STATUS</th> 
</tr></table> 
</body></html>'; 

Hier ist der Code ist die obige Datei als attachemet für das Senden von

// sendign email 
$from = "[email protected]"; 
$subject = "Details\r\n\r\n"; 
$to="[email protected]"; 
$headers = array ('From' => $from, 
'To' => $to, 
'Subject' => $subject); 

$abc="Please find today file attached herewith"; 

$crlf = "\n"; 
$mime = new Mail_mime($crlf); 

    // Setting the body of the email 

    $mime->setHTMLBody($abc); 
$mime->addAttachment($filename, 'text/plain'); 

    $body = $mime->get(); 
    $headers = $mime->headers($headers); 

$smtp = Mail::factory('smtp', 
    array ('host' => $emailhost, 
'auth' => true, 
'username' => '', 
'password' => '')); 


$mail=$smtp->send($to, $headers, $body); 

if (PEAR::isError($mail)) { 
    echo 'There was a problem sending the email.'; 
} else { 
    echo '<br>A message has been sent on your email address '.$cemail; 
} 

?> 

Antwort

0

Verwenden PHPMailer Einbindungsfunktion zu vervollständigen Ihre Aufgabe