Ich habe Stack-Überlauf gesucht und ich kann die Antwort auf mein Problem nicht finden.PHP Pear Mail - Hinzufügen von Zip-Anhang
Ich versuche, eine Zip-Datei als Anhang an eine E-Mail automatisch per PEAR-Mail zu senden. Unten ist der Code, den ich verwende:
require_once "Mail.php";
require_once "mime.php";
$from = '<[email protected]>';
$to = '<[email protected]>';
$subject ='Test stocktake summary reports' ;
//$body = "Hello,\n\nReports for test site have been uploaded and can be accessed by logging in to http://192.168.3.44/ using the following credentials:\n\nusername:testUser \n\npassword:testPassword\n\nKind Regards,\n\n Supervisor Name";
$text = 'Text version of email';
$html = '<html><body>HTML version of email</body></html>';
$file = 'C:/Temp/Reports'.$this->stocktake_id.'.zip';
echo $file;
//die();
$crlf = "rn";
$hdrs = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment($file,'application/zip');
$body = $mime->get();
$hdrs = $mime->headers($hdrs);
$smtp = Mail::factory('smtp', array(
'host' => 'DNS SERVER',
'port' => '465',
'auth' => true,
'username' => 'USERNAME',
'password' => 'PASSWORD'
));
$mail =& Mail::factory('mail', $params);
$mail = $smtp->send($to, $hdrs, $body);
if (PEAR::isError($mail)) {
echo('<p>' . $mail->getMessage() . '</p>');
} else {
echo('<h2>Message successfully sent!</h2>');
}
Der Code funktioniert teilweise. Es sendet die E-Mail, es hängt die Datei an, aber die angehängte Datei heißt "noname" ohne Erweiterung. Ich habe versucht, die $ file-Variable zu wiederholen, um sicherzustellen, dass die richtige Datei ausgewählt wird, und es ist.
Irgendwelche Vorschläge, was das Problem ist?
Vielen Dank!