Moin @ All,
ich verwende ein Script um eine E-Mail mit mehreren Anhängen zu versenden. Das klappt auch wunderbar, bis auf einen kleinen, aber unfeinen Schöhnheitsfehler.
Ohne Anhang sieht die Mail aus wie sie soll. Sobald ich einen Anhang mitgebe erscheint im Mailtext (Body) als erste Zeile diese hier:
Content-Type. text/plain; charset="us-ascii"
Der Rest des Textes ist wieder OK und der Anhang wird auch mit geschickt. Die besagte Zeile steht auch im Script, aber ich weiß nicht wie sie in den Mailbody gelangt. Hat jemand eine Idee?
Die Zeile im Script:
$message .= 'Content-Type. text/plain; charset="us-ascii"'."\n\n" ;
Hier der Code, sorry wenn er ein bißchen umfangreich ist:
<?PHP
define("XNL","\r\n") ; // CONSTANT Newline CR
$mime_boundary = "--==================_846811060==_" ;
$mimetype = "application/octet-stream" ;
function SendMail($ToReceiver, $FromSender, $Subject, $MsgText, $IFile="none", $IFileName="none")
{
global $mimetype, $mime_boundary, $Answer_Reply;
if (!is_array($IFile)) // check for array (multiple attachments)
{
$File[0] = $IFile ;
$FileName[0] = $IFileName ;
}
else
{
for ($i=0;$i<count($IFile);$i++)
{
$File[$i] = $IFile[$i] ;
$FileName[$i] = $IFileName[$i] ;
}
}
$attCount = count($File) ;
$attExists = FALSE ; // check if there is really an attachment
for ($i=0;$i<$attCount;$i++)
{
if ($File[$i] != "none")
{
$attExists = TRUE ;
}
}
$txtheaders = "From: ".$FromSender."\n" ; // build header for text
$txtheaders .= "Reply-To: ".$Answer_Reply."\n" ;
$txtheaders .= "X-Mailer: PHP\n" ;
$txtheaders .= "X-Sender: ".$FromSender."\n" ;
if ($attExists) // is there an attachment
{
// build header for attachment
$attheaders = "MIME-version: 1.0\n" ;
$attheaders .= 'Content-type: multipart/mixed; boundary="'.$mime_boundary.'"'."\n" ;
$attheaders .= "Content-transfer-encoding: 7BIT\n" ;
$attheaders .= "X-attachments: " ;
$firstAtt = TRUE ;
for ($i=0;$i<$attCount;$i++)
{
if ($File[$i] != "none")
{
if ($firstAtt)
{
$firstAtt = FALSE ;
}
else
{
$attheaders .= "," ;
}
$attheaders .= $FileName[$i] ;
}
}
$attheaders .= ";\n\n" ;
// build attachment itself
$attach = "" ;
for ($i=0;$i<$attCount;$i++)
{
if ($File[$i] != "none")
{
$attach .= "--".$mime_boundary."\n" ;
$attach .= "Content-type:".$mimetype.'; name="'.$FileName[$i].'";'."\n" ;
$attach .= "Content-Transfer-Encoding: base64\n" ;
$attach .= 'Content-disposition: attachment; filename="'.$FileName[$i].'"'."\n\n" ;
$attach .= TextEncode($File[$i])."\n" ;
}
}
// build message itself
$message = "--".$mime_boundary."\n" ;
$message .= 'Content-Type. text/plain; charset="us-ascii"'."\n\n" ;
$message .= $MsgText."\n" ;
}
else // no attachment
{
$attheaders = "" ;
$attach = "" ;
$message = $MsgText."\n" ; // send text only
}
// send email
$mail_status=mail($ToReceiver, $Subject, $message.$attach, $txtheaders.$attheaders) ;
}
//
// build attachment as text conforming RFC2045 (76 char per line, end with \r\n)
//
function TextEncode ($FileName)
{
if (is_readable($FileName))
{
$fp = fopen($FileName, "r") ;
$cont = fread($fp, filesize ($FileName)) ;
$contents = base64_encode($cont) ;
$len = strlen($contents) ;
$str = "" ;
while($len > 0)
{
if ($len >= 76)
{
$str .= substr($contents,0,76).XNL ;
$contents = substr($contents, 76) ;
$len = $len - 76 ;
}
else
{
$str .= $contents.XNL ;
$contents = "" ;
$len = 0 ;
}
}
fclose($fp) ;
}
else
{
$str = "File ".$FileName." not found" ;
}
return $str ;
}
?>
regds
Mike©
--
Freunde kommen und gehen. Feinde sammeln sich an.
Freunde kommen und gehen. Feinde sammeln sich an.