kenikavanbis
Terugkerende gebruiker
- Lid geworden
- 22 mei 2007
- Berichten
- 2.192
Best programmeurs ik heb echter een probleem dat ik er niet in slaag een txtmail en htmlmail met inbounded images kan versturen hopelijk zien jullie wat er mis gaat
aanroep
class
aanroep
PHP:
$mymail = new MYmail('test@testdomein.be');
$mymail->setRAWHTMLbody("<html><body>en meer tags from template ter voorbeeld</body><html>");
$mymail->setbody("this is the plain body");
$mymail->send("tester",'test@testdomein.be');
PHP:
<?php
/**
* Atention i use finfo_file from extension=php_fileinfo.dll , --enable-fileinfo
* this is now this format
* +-----------------------------------------------+
* | multipart/related |
* | +---------------------------+ +------------+ |
* | |multipart/alternative | | image/gif | |
* | | +-----------+ +---------+ | | | |
* | | |text/plain | |text/html| | | | |
* | | +-----------+ +---------+ | | | |
* | +---------------------------+ +------------+ |
* +-----------------------------------------------+
* Atention i use finfo_file from extension=php_fileinfo.dll , --enable-fileinfo
* this is was this format
* +--------------------------------+
* | multipart/mixed |
* | | +-----------+ +----------+ |
* | | |text/plain | |attachment| |
* | | +-----------+ +----------+ |
* +--------------------------------+
* @see http://technet.microsoft.com/ja-jp/library/hh547013.aspx#BKMK_MIME_Version
* MIME-Version: 1.0
*/
class MYmail{
private $html;
private $backcolor;
private $bodyparts =array();
private $addparts =array();
private $subject = "ONLY TESTS";
private $headers = array();
private $issend = false;
private $layout;
private $encoding = "utf-8";
private $_END ="\n";
private $SEPARATE ;
private $SEPARATE2;
private $IMGKEY;
private $isimginbedded;
function __construct($from,$name="fromname",$imginbedded =true){
if (strtoupper(substr(PHP_OS,0,3)=='MAC')) { $this->_END="\r";}
if (strtoupper(substr(PHP_OS,0,3)=='WIN')) { $this->_END="\r\n";}
$this->SEPARATE = "*---Boundary-MailPart=_MYTESTMAIL--*".md5(time());
$this->SEPARATE2 = $this->SEPARATE."_2";
$this->IMGKEY="".md5(time());"";
$this->headers["From:"] = "$name <$from>".$this->_END;
$this->headers["Reply-To:"] = "$from <$from>".$this->_END;
$this->headers["MIME-Version:"] = "1.0".$this->_END;
$this->headers["TO:"] = "".$this->_END;
$this->headers["Subject:"] = "".$this->_END;
$this->headers["Date:"] = $today = date('d M Y g:i:s').$this->_END;
//$this->headers["Content-Type:"] = 'multipart/mixed; boundary="'.$this->SEPARATE.'"'.$this->_END;//'.$this->_END."\t\t".'
//$this->headers["Content-Type:"] = 'multipart/alternative; boundary="'.$this->SEPARATE.'"'.$this->_END;
$this->headers["Content-Type:"] = ' multipart/related;'.$this->_END.'boundary="'.$this->SEPARATE.'"'.$this->_END;
$this->headers["Content-Disposition:"]= "attachment".$this->_END;
//$this->headers["Content-Disposition:"]= "attachment".$this->_END;
//$this->bodyparts['body']= "";
//$this->setbody("this is the plain text");
print("construct");
$this->isimginbedded = $imginbedded;
}
/**
* @maillist
* asiosiatieve array (name => mail)
*/
function maillist($array){
(is_array($array)) ? array_walk($array, 'send') : null;
}
/**
* Mymail::send()
* @param $naam naam verzender
* @param $email email adress
* @return boolean
* @walkit
* !important! do not remake watch to array_walk
*/
public function send($naam, $email){
$this->headers["TO:"] = "$naam <$email>".$this->_END;
print "<pre>header:".$this->_END.$this->getheaders()."\nxbody:".$this->_END.$this->getbody()."</pre>";
$this->issend = mail($email, $this->subject,$this->getbody(),$this->getheaders());
/*if($this->issend){
print(" mogelijks verzonden");//.$email." ".$this->subject." ".$this->getbody()." ".$this->getheaders());
}else{
print("mogelijks niet verzonden");
}*/
return $this->issend;
}
public function printAsSend($naam, $email){
print "<pre>header:".$this->_END.$this->getheaders()."\nbody:".$this->_END.$this->getbody()."</pre>";
}
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< HEADERS>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
/**
* Mymail::getheaders()
* @return
*/
private function getheaders(){
$return ="";
foreach($this->headers as $key => $value){//let op psCode
$return .= $key . "" . $value;
}
return $return;
}
/**
* Mymail::sethtml()
* @return void
*/
private function sethtml(){
$this->headers["Content-Type:"] = " text/html; charset='iso-8859-1'";
}
/**
* Mymail::setsubject()
* @return void
*/
public function setsubject($subject){
$this->subject = $subject;
}
/**
* Mymail::setmultipart()
* @return void
*/
private function setmultipart(){
$this->headers["Content-Type:"] = 'multipart/mixed; boundary="'.$this->SEPARATE.'"'.$this->_END;
}
/**
* Mymail::setmultipart()
* @return void
*/
private function setmultipartalternative(){
$this->headers["Content-Type:"] = 'MIME-Version: 1.0'."\n".'Content-Type: multipart/alternative; boundary="'.$this->SEPARATE.'"'.$this->_END;
}
//
/**
* Mymail::is_headerinject()
* @param mixed $from
* @return
*/
private function is_headerinject($from){
//%0D%0A HTML-equivalent => \r\n
return pos($var, "%0D%0A") || pos($var, "%0D%0Abcc:");
}
/**
* Mymail::is_spammer()
* @param mixed $from
* @return
*/
private function is_spammer($from){
return $this->is_headerinject($from);
}
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< BODY>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
/**
* Mymail::getbody()
* @return
*/
private function getbody(){
$body ="";
$body.= "This is a multipart message in MIME format.".$this->_END.$this->_END;
$body.= $this->getpartstart()."Content-Type: multipart/alternative;".$this->_END.'boundary="'.$this->SEPARATE2.'"'.$this->_END.$this->_END;
if($this->bodyparts['plainbody']!="" && $this->bodyparts['HTMLbody']!=""){
$body .= $this->getpartstart2().$this->bodyparts['plainbody'];
$body .= $this->getpartstart2().$this->bodyparts['HTMLbody'];
//$REL = "*---Boundary-Inner_Part=_My--*".md5(time());
//$rel=$this->getpartstart().$this->_END."Content-Type: multipart/related;".$this->_END.
//'boundary="'.$REL.'"';
$body .= "--".$this->SEPARATE2."--".$this->_END.$this->_END;
}
foreach($this->addparts as $key=>$value){
$body .= $this->getpartstart().$value;
}
$body .= "--".$this->SEPARATE."--";
return $body;
}
/**
* Mymail::setbody()
* @IMPORTANT !!! finish with two end of line's for better security. !!!
* @param mixed $body
* @return void
* @see Injection. two end of line's for better security.
*/
public function setbody($body){ // '.$this->_END.'
$this->bodyparts['plainbody']= 'Content-Type: text/plain; charset="'.$this->encoding.'";'.$this->_END.
//"Content-Transfer-Encoding: quoted-printable ".$this->_END.
"Content-Transfer-Encoding: 7bit".$this->_END.$this->_END.
$body.
$this->_END.$this->_END;
}
/**
* Mymail::setbody()
* @IMPORTANT !!! finish with two end of line's for better security. !!!
* @param mixed $body
* @return void
* @see Injection. two end of line's for better security.
*/
public function setHTMLbody($body){//'.$this->_END."\t\t".'
$this->bodyparts['HTMLbody']= 'Content-Type: text/html; charset="'.$this->encoding.'";'.$this->_END.
//"Content-Transfer-Encoding: quoted-printable ".$this->_END.
"Content-Transfer-Encoding: 7bit".$this->_END.$this->_END.
"<html><body>".$this->Aln2space($body)."</body></html>".$this->_END.$this->_END;
}
/**
* Mymail::setbody()
* @IMPORTANT !!! finish with two end of line's for better security. !!!
* @param mixed $body
* @return void
* @see Injection. two end of line's for better security.
*/
public function setRAWHTMLbody($body){//'.$this->_END."\t\t".'
$this->bodyparts['HTMLbody']= 'Content-Type: text/html; charset="'.$this->encoding.'";'.$this->_END.
//"Content-Transfer-Encoding: quoted-printable ".$this->_END.
"Content-Transfer-Encoding: 7bit".$this->_END.$this->_END.
"".$this->Aln2space($body)."".$this->_END.$this->_END;
}
/**
* Mymail::Aln2br()
*
* @param mixed $txt
* @return boolean
*/
private function Aln2br($txt){
return strtr($txt, array("\r\n" => '<br />', "\r" => '<br />', "\n" => '<br />'));
}
/**
* Mymail::Aln2br()
*
* @param mixed $txt
* @return boolean
*/
private function Aln2space($txt){
return strtr($txt, array("\r\n" => '', "\r" => '', "\n" => ''));
}
/**
* Mymail::getpartstart()
* @return
*/
public function getpartstart(){
return "--".$this->SEPARATE."". $this->_END;
}
/**
* Mymail::getpartstart()
* @return
*/
public function getpartstart2(){
return "--".$this->SEPARATE2. $this->_END;
}
/**
* Mymail::wrap_each()
* @param mixed $item
* @return void
*/
function wrap_each(&$item){
$item = "'$item'";
}
/**
* IMAPMAIL::dMyde()
* @param mixed $text
* @param mixed $TYPE 'SJIS','UTF-7','EUC-JP','JIS','UCS-2LE','eucjp-win','sjis-win'
* @param mixed $TYPEfrom 'auto','SJIS','UTF-7','EUC-JP','JIS','UCS-2LE','eucjp-win','sjis-win'
* @return
*/
public function encode(&$text,$TYPE,$TYPEfrom=""){
if (isset($TYPEfrom)&&$TYPEfrom!=''){
mb_convert_encoding($text,$TYPE);
}else{
mb_convert_encoding($text ,$TYPE,$TYPEfrom);
}
}
/**
* Mymail::addattachment()
* @param mixed $filename
* @return void
*/
public function addattachment($filename,$END){
if (is_file($filename)){
$finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
$fileatt_type = finfo_file($finfo, $filename); //$fileatt_type = mime_content_type($filename);(OLD CODE)
$fileatt_name = $filename; // Filename that will be used for the file as the attachment
$file = fopen($filename, 'rb');
$bestandsinf = fread($file, filesize($filename));//TODO if error on this line posible file exist but is empty
$bestandsinf.=$END;
fclose($file);
$data = chunk_split(base64_encode($bestandsinf));//
$name= substr(strrchr($filename,'.'),1);
$attachment= 'Content-Type: application/octet-stream;'.' name='.$filename.$this->_END.
"Content-Transfer-Encoding: base64".$this->_END.
"Content-Disposition: attachment;".$this->_END.
$this->_END.$data.$this->_END;
array_push($this->addparts,$attachment);
}else{
print "attachment does not exist";
}
}
public function checkforimgtag(&$html){
}
/**
* TODO//uncontstruct
* Mymail::addattachment()
* @param mixed $filename
* @return cdi:$lable
*/
public function addimg($filename,$inbedded =true){
if (is_file($filename)){
$pos = strrpos($filename, "/");
if(is_bool($pos) && !$pos) {
$name = $filename;
}else{
$name = substr($filename,$pos);
}
$finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
$fileatt_type = finfo_file($finfo, $filename); //$fileatt_type = mime_content_type($filename);(OLD CODE)
$fileatt_name = $filename; // Filename that will be used for the file as the attachment
$file = fopen($filename, 'rb');
$bestandsinf = fread($file, filesize($filename));//TODO if error on this line posible file exist but is empty
fclose($file);
$data = chunk_split(base64_encode($bestandsinf));
$name= substr(strrchr($filename,'/'),1);
$cdi = $name."@".$this->IMGKEY;
$attachment= 'Content-Type: '.$fileatt_type.';'.'name="'.$name.'"'.$this->_END.
"Content-Transfer-Encoding: base64".$this->_END.
"Content-ID: <$cdi>".$this->_END.
"Content-Disposition: inline;".
$this->_END.$data.$this->_END;
array_push($this->addparts,$attachment);
}else{
print "attachment does not exist";
}
return $cdi;
}
}
?>
Laatst bewerkt: