Hallo,
ich habe eine Klasse Mail
Code:
class Mail
{
private $subject;
private $sender;
private $recipients;
private $replyto;
private $textbody;
private $htmlbody;
private $type;
const TYPE_TEXT = 0;
const TYPE_HTML = 1;
const TYPE_MULTI = 2;
function __construct($recipients, $sender, $subject = "", $textbody = "", $htmlbody = "", $replyto = "", $type = 0){
$this->recipients = $recipients;
$this->sender = $sender;
$this->subject = $subject;
$this->replyto = $replyto;
$this->textbody = $textbody;
$this->htmlbody = $htmlbody;
$this->type = $type;
}
function __destruct(){
}
public function getSubject(){
return $this->subject;
}
public function setSubject($subject){
$this->subject = $subject;
}
public function getReplyTo(){
return $this->replyto;
}
public function setReplyTo($replyto){
$this->replyto = $replyto;
}
public function getRecipients(){
return $this->recipients;
}
public function setRecipients($recipients){
$this->recipients = $recipients;
}
public function getSender(){
return $this->sender;
}
public function setSender($sender){
$this->sender = $sender;
}
public function getTextBody(){
return $this->textbody;
}
public function setTextBody($textbody){
$this->textbody = $textbody;
}
public function getHtmlBody(){
return $this->htmlbody;
}
public function setHtmlBody($htmlbody){
$this->htmlbody = $htmlbody;
}
public function getType(){
return $this->type;
}
public function setType($type){
$this->type = $type;
}
}
und ich habe eine Klasse UserMail, die von Mail abgeleitet ist.
Code:
class UserMail extends Mail
{
private $ecard_id;
private $recipient;
private $mail;
function __construct($ecard_id){
global $customers;
$this->ecard_id = $ecard_id;
try{
$inxcon = new Inxmail_Connection("http://".$customers["rabbit"]["campaignserver"].$customers["rabbit"]["campaignaccount"],$customers["rabbit"]["campaignapiuser"],$customers["rabbit"]["campaignapipassword"],"system");
$recs = $inxcon->getRecipentsByAttrValue("ecard_id",$this->ecard_id);
if($recs[0] instanceof Recipient){
$this->recipient = $recs[0];
}else{
throw new Exception("Error while selecting user from database."."<p>".$this->ecard_id."</p><p>Number Recs: ".count($recs)."</p>");
}
}catch(Exception $e){
throw $e;
}
$html;
$text;
if(isset($customers[$this->recipient->getAttribute("customer")])){
try{
$html = $this->readFile("templates/".$this->recipient->getAttribute("customer")."_html.html");
$text = $this->readFile("templates/".$this->recipient->getAttribute("customer")."_text.txt");
}catch(Exception $e){
throw $e;
}
//Parse Fields
$html = $this->parseMailContent($this->recipient, $html, true);
$text = $this->parseMailContent($this->recipient, $text);
//Parse Module Presents
$html = $this->parsePresent($this->recipient,$html,true);
$text = $this->parsePresent($this->recipient,$text);
//Parse Onlinelink
$html = $this->parseOnlineLink($this->recipient,$html);
$text = $this->parseOnlineLink($this->recipient,$text);
//Parse Confirm Link
$html = $this->parseConfirmLink($this->recipient,$html);
$text = $this->parseConfirmLink($this->recipient,$text);
//initialize Mailing
/*
$mail = new Mail();
$mail.setHtmlBody($html);
$mail.setTextBody($text);
$mail.setRecipients($this->recipient->getAttribute("email"));
$mail.setSender($this->recipient->getAttribute("sender_email"));
$mail.setSubject($this->recipient->getAttribute("sender_vorname")." ".$this->recipient->getAttribute("sender_nachname")." sendet Ihnen weihnachtliche Gr��e");
$mail.setType($i = 2);
*/
parent::setHtmlBody($html);
parent::setTextBody($text);
parent::setRecipients($this->recipient->getAttribute("email"));
parent::setSender($this->recipient->getAttribute("sender_email"));
parent::setSubject($this->recipient->getAttribute("sender_vorname")." ".$this->recipient->getAttribute("sender_nachname")." sendet Ihnen weihnachtliche Gr��e");
parent::setType(2);
}else{
throw new Exception("Customer does not exist.");
}
}
function __destruct(){
}
/**
* Returns this Mailing.
*
* @return unknown
*/
public function getEcardId(){
return $this->ecard_id;
}
/**
* Returns a String value of the file content.
* Use with text files only.
*
* @param unknown_type $file
* @return unknown
*/
private function readFile($file){
$fh = fopen($file,"r");
$f;
if($fh){
$f = fread($fh,filesize($file));
}else{
throw new Exception("Could not open File ".$file.".");
fclose($fh);
}
fclose($fh);
return $f;
}
/**
* Every appearence of the arrays key value in $text ([key]) will be replaced by the Arrays value.
* If encryption is set to true, all passed values will be html encoded.
*
* @param array $arr
* @param unknown_type $text
* @param unknown_type $enc
* @return unknown
*/
private function parseMailContent(Recipient $rec, $text, $enc = false){
$ret = $text;
foreach($rec->getAttributes() as $key => $val){
if($enc == true){
$val = htmlentities($val,null,"utf-8");
}
$ret = str_ireplace("[".$key."]",$val,$ret);
}
return $ret;
}
/**
* This method replaces [@$var[customer]_geschenke] with the three persents the sender picked.
* If encryption is set to true, all passed values will be html encoded.
*
* @param unknown_type $var
* @param unknown_type $text
* @param unknown_type $enc
*/
private function parsePresent(Recipient $rec,$text, $enc = false){
global $customers;
$presents[] = $rec->getAttribute("produkt_1");
$presents[] = $rec->getAttribute("produkt_2");
$presents[] = $rec->getAttribute("produkt_3");
$con;
foreach($presents as $val){
switch($val){
case 1:
$con[] = $customers[$rec->getAttribute("customer")]["present1"];
break;
case 2:
$con[] = $customers[$rec->getAttribute("customer")]["present2"];
break;
case 3:
$con[] = $customers[$rec->getAttribute("customer")]["present3"];
break;
case 4:
$con[] = $customers[$rec->getAttribute("customer")]["present4"];
break;
case 5:
$con[] = $customers[$rec->getAttribute("customer")]["present5"];
break;
case 6:
$con[] = $customers[$rec->getAttribute("customer")]["present6"];
break;
case 7:
$con[] = $customers[$rec->getAttribute("customer")]["present7"];
break;
case 8:
$con[] = $customers[$rec->getAttribute("customer")]["present8"];
break;
case 9:
$con[] = $customers[$rec->getAttribute("customer")]["present9"];
break;
case 10:
$con[] = $customers[$rec->getAttribute("customer")]["present10"];
break;
}
}
$ret = implode(", ",$con);
if($enc == true){
$ret = htmlentities($ret,null,"utf-8");
}
$text = str_ireplace("[@".$rec->getAttribute("customer")."_geschenke]",$ret,$text);
return $text;
}
private function parseOnlineLink(Recipient $rec, $text){
global $app_path;
$onlinelink = "http://".$_SERVER['SERVER_NAME'].$app_path."/show.php5?customer=".$rec->getAttribute("customer");
$onlinelink .= "&ecard_id=".$rec->getAttribute("ecard_id");
$text = str_ireplace("[%application-url]/html_mail.jsp?params=[%online_params]",$onlinelink,$text);
return $text;
}
private function parseConfirmLink(Recipient $rec, $text){
global $app_path;
$link = "http://".$_SERVER['SERVER_NAME'].$app_path."/show.php5?ecard_id=".$rec->getAttribute("ecard_id")."&confirm=1";
$text = str_ireplace("[@confirmlink]",$link,$text);
return $text;
}
public function getMail(){
return $this->mail;
}
}
Es ist mir nicht möglich, in UserMail auf die geerbten Methoden aus Mail zuzugreifen.
Der betreffende Teil steht am Ende des Konstruktors. Ich setze alle Werte für UserMail über parent::setHtmlBody() etc.
Leider bekomme ich ständig folgenden Fehler:
Code:
Fatal error: Call to undefined method Mail::sethtmlbody() in /kunden/127589_60329/subdomains/demo/timo/classes/UserMail.php on line 62
Ich habe den halben Tag gegoogelt um was dazu zu finden, aber alle Beispiele funktionieren nach diesem Muster. Habe ich was übersehen?