so, hab mich as erste mal mit anhängen beschäftigt, habs vorher nie gebraucht.
is aber gar nicht mal so schwer.
hier mal eine kleine klasse, ist abgespeckt, im orginal etwas komplexer.
vielleicht braucht sie ja wer
< ?php
class mail_class {
var $to = '';
var $subject = '';
var $content = '';
var $header = '';
var $attach_header = false;
var $attach_border = false;
var $search = array();
var $replace = array();
/**
* Validate a email
* @param string $email URL to validate
* @return boolean true if valid email, false if not
* http://cvs.php.net/co.php/pear/Validate/Validate.php?r=1.68#124 (changed by bjoern)
*/
function check_email($email) {
// "Borrowed" from PEAR::HTML_QuickForm
$regex = '/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+'.
'(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|'.
'(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|'.
'([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))'.
'\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|'.
'(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|'.
'([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))'.
'\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|'.
'((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/';
if (preg_match($regex, $email)) return true;
else return false;
}
function send_mail($html=0,$absender,$reply_to) {
$this->header = '';
$this->header .= 'From: P2Office < '.$absender.">\r\n";
$this->header .= 'Reply-To: '.$reply_to."\nX-Mailer: PHP/" . phpversion()."\r\n";
if($this->check_email($this->to)) {
$this->send_the_attach();
mail($this->to,$this->subject,$this->content,$this->header);
#log::do_log('Email mit Subject: "'.$this->subject.'" an '.$this->to.' versendet.');
}
}
function send_the_attach() {
if($this->attach_border && $this->attach_header) {
$this->header = $this->header . $this->attach_header . "--".$this->attach_border;
}
}
function create_attach_border($name) {
$this->attach_border = md5($name);
$this->attach_header = "Content-Type: multipart/mixed;\n\tboundary=".$this->attach_border."\n";
}
function add_attach($file,$name,$typ) {
if(!$this->attach_border) $this->create_attach_border($name);
if(!file_exists($file)) return false;
$attach_data = implode("",file($file));
$attach_data = chunk_split(base64_encode($attach_data));
$this->attach_header .= "\n--".$this->attach_border."\n";
switch($typ) {
case 'pdf':
$this->attach_header .= "Content-Type: application/pdf;\n\t";
break;
case 'html':
$this->attach_header .= "Content-Type: text/html;\n\t";
break;
}
$this->attach_header .= "name=".$name."\n";
$this->attach_header .= "Content-Transfer-Encoding: base64\n";
$this->attach_header .= "Content-Disposition: attachment;\n\tfilename=".$name."\n\n";
$this->attach_header .= $attach_data;
$this->attach_header .= "\n\n";
}
}
$mail = new mail_class();
$mail->add_attach('1001.pdf','1001.pdf','pdf');
$mail->add_attach('1000.pdf','1000.pdf','pdf');
$mail->to = 'email@domain.de';
$mail->subject = 'Testemail mit zwei anhängen!';
$mail->content = 'LALA mein inhalt!!!';
$mail->send_mail(0,'absender@domain.de','reply-to@domain.de');
?>
evtl müsst ihr noch mehr „Content-Type“s einfügen, hab aktuell nur pdf und html
der rest sollte selbsterklärend sein
mfg