Toon posts:

[PHP] attachment ?simpel?

Pagina: 1
Acties:

Verwijderd

Topicstarter
Is er ook een makkelijkere manier om met een mailtje een attachment mee te sturen (-- mail() --)?
Mime header is er al maar daaraan wil ik een file toevoegen die mee gestuurd wordt.

Kan op het net wel zooi vinden die het kan, maar dat zijn allemaal apparte classes. Applicatie is al af en daarom is het te lastig om al die zooi weer om te gooien om die classes in te bouwen.

$te_temp = $te;
$te = "This is a multi-part message in MIME format.\n\n";
$te .= "--_grens_\n";
$te .= "Content-Type: text/plain; charset=\"iso-8859-1\"\nContent-Transfer-Encoding: quoted-printable\n\n";
$te .= "$de\n"; <-- text versie van mail
$te .= "--_grens_\n";
$te .= "Content-Type: text/html; charset=\"iso-8859-1\"\nContent-Transfer-Encoding: 7-bit\n\n";
$te .= "$te_temp"; <-- html versie van mail

Hier moet dan ergens ook het attachment worden meegegeven en gecodeerd. Iemand suggesties?

  • bigtree
  • Registratie: Oktober 2000
  • Laatst online: 07-07 11:51
Onderaan toevoegen (voorbeeldje met .zip bestand):

$te .= "--_grens
Content-Type: application/x-zip-compressed;
name="attachment.zip"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="attachment.zip"

<attachment.zip in base64>

--_grens--";

Lekker woordenboek, als je niet eens weet dat vandalen met een 'n' is.


  • me1299
  • Registratie: Maart 2000
  • Laatst online: 19:37

me1299

$ondertitel

Waarom is dat eigenlijk zo ingewikkeld met php. Ik kan herinneren met ASP dat het veel makkelijker ging :?

Het maakt eigenlijk niet uit wat je bewuste geest doet, omdat je onderbewuste automatisch precies dat doet wat het moet doen


  • frosty1878
  • Registratie: Juli 2001
  • Laatst online: 24-01 11:33
bestudeer deze klasse eens, moet het mee lukken.. su6

<?php
/************************************
author : Eric Kerst
class : MIME_mail
description : class for mail distribution
version : 1.0
date (la) : 12/13/00 10:54AM
updates:
-
known problems/bugs:
-
future updates:
-
**************************************/

define("GMT", "+0200");
define("LF", "\r\n");
define("TAB", "\t");
//define("LF", "<br>");
define("BODY", md5("BODY"));
define("WARNING", "This message is in MIME format. The first part should be readable text, \r\nwhile the remaining parts are likely unreadable without MIME-aware tools.");

class MIME_mail {

// Declaration of public variables
var $From;
var $To;
var $Cc;
var $Bcc;
var $Subject;
var $Body;

var $Email = "";

// Declaration of private variables
var $Mimeparts = array();

// Constructor

function MIME_mail($From, $To, $Cc="", $Bcc="", $Subject="No subject", $Body) {
//Func - Constructs a MIME mail
//Pre - $From=true, $To=true, $Body=true
//Post - MIME_mail=true

// Assign given values to public variables
$this->From = $From;
$this->To = $To;
$this->Cc = $Cc;
$this->Bcc = $Bcc;
$this->Subject = $Subject;
if ($Body =="") $this->Body = "no content"; else $this->Body = $Body;

}

// Methods

function Attach($Data, $Description="", $Contenttype, $Encoding="base64", $Fname="") {
//Func - Creates attachment and puts it on the Mimeparts stack
//Pre - $Data=true, if only data is entered, it we'll be coded in base64
//Post - true (Mimeparts[+1]) or false

// When no data found return false
if (empty($Data)) return false;
// If description is not empty, prepare it for insert in attachmentheader
if (!($Description=="")) $Descheader = "Content-Description: ".$Description.LF;
// Check which encoding type is used
switch ($Encoding) {
// When qp is found, rename the encoding "qouted-printable"
case "qp" :$Encoding="quoted-printable";
$Emsg=$Data;
break;
// When encodig is BASE64, encode it with php func. base64_enc
case "base64" : $Emsg = base64_encode($Data);
break;
}
// Split message in chunks to match RFC 2045 semantics
$Emsg = chunk_split($Emsg);
// Check which contenttype is used
switch ($Contenttype) {
// When $Contenttype == text the type is text/plain and charset=us-ascii
case "text": $Contenttype="text/plain";
$Charset = "charset=\"iso-8859-1\"";
break;
// Same as above, but now with html
case "html": $Contenttype="text/html";
$Charset= "charset=\"iso-8859-1\"";
break;
// On default we asume it's a file
default: $Charset = "name=\"$Fname\"";
$Cdisp = "Content-Disposition: attachment;";
$Filename = "filename=\"$Fname\"";
}
// creation of attachment header
$Msg = "Content-Type: ".$Contenttype.";".LF.TAB.$Charset.LF;
$Msg.= "Content-Transfer-Encoding: ".$Encoding.LF;
// when encoding is base64
if ($Encoding=="base64")
$Msg.= $Descheader.$Cdisp.LF.TAB.$Filename.LF.LF;
else $Msg.= LF;
$Msg.= $Emsg.LF;
// Put $Msg on Mimeparts stack
if ($Description==BODY)
$this->Mimeparts[0] = $Msg;
else $this->Mimeparts[(count($this->Mimeparts)+1)] = $Msg;
// return amount of parts in stack
return count($this->Mimeparts);
}

function Build_Message() {
//Func - Builds the message, private function
//Pre -
//Post -

// Assign empty string to Msg variable
$Msg = "";
// Create unique boundary string
$Boundary = "PM".chr(rand(65, 91))."------".md5(uniqid(rand()));
// Count amount of Mimeparts that exists in Mimeparts array
$Mparts = count($this->Mimeparts);
// Create random value to be sure a unique X-Sent header is created
srand((double)microtime()*1000000);
$Randval = rand();
// XMail parts, need to be added after MIME headers
$XMail ="X-Mailer: AMPM".LF;
$XMail.="X-Send: ".$Randval.LF;
// An attachment list is found (>0), therefore MIME message header has to be
// Multipart/Mixed
if ($Mparts > 0) {
$Ver = "MIME-Version: 1.0".LF;
$Type = "Content-Type: multipart/mixed;".LF.TAB."boundary=\"".$Boundary."\"".LF;
$Warning = LF.WARNING.LF;
// Add text message to Mimepart stack.
if (!empty($this->Body)) {
$this->Attach($this->Body, BODY, "text", "qp");
$Mparts++;
}
// Create mail from MIME-parts
for ($I=0;$I<$Mparts;$I++)
if (!empty($this->Mimeparts[$I]))
$Msg.= LF."--".$Boundary.LF.$this->Mimeparts[$I];
$Msg.= "--".$Boundary."--".LF;
$Msg = $Ver.$Type.$XMail.$Warning.$Msg;
} else if (!empty($this->Body)) {
$Ver = "MIME-Version: 1.0".LF;
$Contenttype="Content-Type: text/plain;".LF.TAB."charset=\"iso-8859-1\"".LF;
$Msg.= $Ver.$Contenttype.$XMail.LF.$this->Body.LF;
}
if (strlen($Msg) == 0) $Msg = LF.LF;
return $Msg;
}

function Gen_Mail($Force=false){
//Func - Generates the MIME-mail messages using the private Build_Message function
//Pre -
//Post -

// Returns Email if already processed.
if (!empty($this->Email) && (!$Force)) return $this->Email;
$Email = "";
if (!empty($this->From)) $Email ="From: ".$this->From.LF;
if (!empty($this->To)) $Email.="To: ".$this->To.LF;
if (!empty($this->Cc)) $Email.="Cc: ".$this->Cc.LF;
if (!empty($this->Bcc)) $Email.="Bcc: ".$this->Bcc.LF;
$Email.="Subject: ".$this->Subject.LF;
$Email.="Date: ".date("D, j M Y G:i:s")." ".GMT.LF;
// Add attachments
$Email.= $this->Build_Message();
$this->Email = $Email;
//
return $this->Email;
}

}
?>

-- keep it clean


  • me1299
  • Registratie: Maart 2000
  • Laatst online: 19:37

me1299

$ondertitel

Thanx m8, dat zou voor mij ook wel eens handig uit kunnen pakken! *D

Het maakt eigenlijk niet uit wat je bewuste geest doet, omdat je onderbewuste automatisch precies dat doet wat het moet doen


  • tomato
  • Registratie: November 1999
  • Niet online
Op maandag 05 november 2001 19:18 schreef DeathKnight het volgende:
Waarom is dat eigenlijk zo ingewikkeld met php. Ik kan herinneren met ASP dat het veel makkelijker ging :?
In PHP is het niet moeilijker dan in ASP. Je bent zeer waarschijnlijk componentjes gewend voor ASP die dit werk doen (cdonts?), er zijn ook zat mensen die een email laag voor PHP gemaakt hebben.
Pagina: 1