"Descrizione destinatario" * @param string $oggetto Oggetto della mail * @param string $testo Testo della mail, eventualmente in html (completo di tag body) * @param array $allegati Array che associa al "nome del file (completo di percorso)"=> "un nome descrittivo" se stringa vuota si usa il nome del file senza percorso * @return void */ function MyMail($nome_mittente,$email_mittente,$email_destinatari,$oggetto='',$testo='',$allegati=array()){ static $NEmbedded; $this->NEmbedded=&$NEmbedded; $this->Priority =1; $this->PluginDir=dirname(__FILE__)."/phpmailer/"; $this->SetLanguage('it',dirname(__FILE__)."/phpmailer/language/"); $this->FromName =$nome_mittente; $this->From =$email_mittente; $this->Subject= $oggetto; $this->Set_Testo($testo); ob_start(); try{ if (!is_array($email_destinatari)) $email_destinatari=array($email_destinatari); foreach ($email_destinatari as $k=>$v) { if (!is_string($k)) $this->AddAddress($v); else $this->AddAddress($k,$v); } if (is_array($allegati)) foreach ($allegati as $file=>$nome) $this->AddAttachment($file,$nome); $this->IsSMTP(); } catch (Exception $e) {} ob_end_clean(); } /** * Imposta la richiesta di conferma * @param string $email email a cui indirizzare la conferma apertura email,se omesso si usa l'indirizzo del mittente * @return void */ function set_conferma($email='') { if(strpos($email,'@')===false) $this->ConfirmReadingTo=$this->From; else $this->ConfirmReadingTo=$email; } /** * Setta l'oggetto della mail * @param string $oggetto * @return void */ function Set_oggetto($oggetto){ $this->Subject= $oggetto; return $this; } /** * Setta il testo delle mail * @param string $testo Testo della mail, eventualmente in html (completo di tag body) * @return void */ function Set_Testo($testo){ $this->Body=$testo; $this->IsHTML(strip_tags($this->Body)!=$this->Body); return $this; } /** * Restituisce l'Id della mail inviata * @return string */ function get_Id_mail(){ return $this->LastId; } /** * restituisce l'ultimo errore trovato * * @return string */ function get_last_error() { return $this->ErrorInfo; } /** * Invia la mail se c'è errore lo restituisce * @return string */ function Send() { try{ if (!$this->Body) return; if (strip_tags($this->Body)==$this->Body) { $this->IsHTML(false); } else{$this->IsHTML(true); $this->Body=$this->IncorporaImmagini(); $this->AltBody =$this->solotesto($this->Body); } $this->ErrorInfo=false; ob_start(); parent::Send(); $out=trim(ob_get_clean()); if($this->ErrorInfo) return $this->ErrorInfo; else return $out; } catch (Exception $e) {return $e->getMessage();} } /** * Aggiunge un allegato alla mail * @param string $path E' il percorso del file da allegare * @param string $name E' il nome da dare al file allegato all'interno della mail * @return void */ function AddAttachment($path, $name = ""){ if (!is_file($path)) return; try { return parent::AddAttachment($path,$name,"base64", $this->mime_content_type($path)); } catch (Exception $e) {} } /** * Aggiunge un destinatario * @param string $address indirizzo email * @param string $name Eventuale nome descrittivo associato alla mail * @return void */ function AddAddress($address, $name = "") { try{if (strpos($address,'@')!==false) parent::AddAddress($address, $name); } catch (Exception $e) {} return $this; } /** * Aggiunge un destinatario in conoscenza "Cc" * @param string $address indirizzo email * @param string $name Eventuale nome descrittivo associato alla mail * @return void */ function AddCC($address, $name = "") { try{ parent::AddCC($address, $name); } catch (Exception $e) {} return $this; } /** * Aggiunge un destinatario in conoscenza nascosta "Ccn" * @param string $address indirizzo email * @param string $name Eventuale nome descrittivo associato alla mail * @return void */ function AddCCn($address, $name = "") { try{ $this->AddBCC($address, $name); } catch (Exception $e) {} return $this; } /** * Aggiunge un destinatario a cui i rispondere * @param string $address indirizzo email * @param string $name Eventuale nome descrittivo associato alla mail * @return void */ function AddReplyTo($address, $name = "") { try{ parent::AddReplyTo($address, $name); } catch (Exception $e) {} return $this; } /** @ignore */ function nonhtmlentities($text) { $trans_tbl = get_html_translation_table(HTML_ENTITIES); $trans_tbl = array_flip($trans_tbl); $trans_tbl['€']='€'; $trans_tbl[' ']=' '; $text = strtr($text, $trans_tbl); $text = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $text); $text = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $text); return $text; } /** @ignore */ function solotesto($testo) { $v=preg_split('@@',$testo); if (count($v)>=2) $testo='nonhtmlentities($testo); $testo=preg_replace("#')); $testo=preg_replace('/(.*?)<\\/a>/iU',"\$4 (\$2)", $testo); return $testo; } /** @ignore */ function mime_content_type($file){ $file_extension=explode('.',strtolower($file)); $file_extension=$file_extension[count($file_extension)-1]; return $this->_mime_types($file_extension); } /** @ignore */ function AddStringImage($file, $cid, $name = "", $encoding = "base64") { $cur = count($this->attachment); $this->attachment[$cur][0] = $file; $this->attachment[$cur][1] = $name; $this->attachment[$cur][2] = $name; $this->attachment[$cur][3] = $encoding; $this->attachment[$cur][4] = $this->mime_content_type($name); $this->attachment[$cur][5] = true; // isStringAttachment $this->attachment[$cur][6] = "inline"; $this->attachment[$cur][7] = $cid; return true; } /** @ignore */ function embedElement($im) { if($this->NEmbedded[$im]) return "cid:MyEmbedded_".$this->NEmbedded[$im]; { $file=null; if($im{0}=='/') $file="$_SERVER[DOCUMENT_ROOT]$im"; elseif (is_file($im)) $file=$im; elseif(strpos($im,'http')===0 || (strpos($im,"://$_SERVER[SERVER_NAME]") || strpos($im,"://$_SERVER[SERVER_ADDR]")) ) $file=$im; if ($file!==null && is_file($file)) {$this->NEmbedded[$im]=count($this->NEmbedded); try{ $this->AddEmbeddedImage(realpath($file),"MyEmbedded_".$this->NEmbedded[$im],basename($file),'base64',$this->mime_content_type($file)); } catch (Exception $e) {} return "cid:MyEmbedded_".$this->NEmbedded[$im]; } } } /** @ignore */ function embedElements(&$elementi,$testo) { foreach ($elementi as $i=>$im) if($im && !$gia_fatta[$im]) { $gia_fatta[$im]=1; $file=null; if($im{0}=='/' && is_file("$_SERVER[DOCUMENT_ROOT]$im")) $file="$_SERVER[DOCUMENT_ROOT]$im"; elseif (is_file($im)) $file=$im; elseif(strpos($im,'http')===0 || (strpos($im,"://$_SERVER[SERVER_NAME]") || strpos($im,"://$_SERVER[SERVER_ADDR]")) )$file=$im; $contenuto = ''; if(is_file($file)) {$i=++$this->NEmbedded; try{ $this->AddEmbeddedImage(realpath($file),"MyEmbedded_$i",basename($file),'base64',$this->mime_content_type($file)); } catch (Exception $e) {} $testo=preg_replace('~'.$attr.'=[\'"]'.$im.'[\'"]',"$attr='cid:MyEmbedded_$i'~mU", $testo); } } return $testo; } /** @ignore */ function CreateHeader() { try{ $header=parent::CreateHeader(); preg_match("/Message-ID: <(.*)>/i",$header,$trovato); if (count($trovato)==2) $this->LastId=$trovato[1]; else $this->LastId=null; } catch (Exception $e) {} return $header; } /* function Check_Id($mail_id,$user='',$pass=''){ if (!is_array($mail_id)) $mail_id=array(); $pop=new POP3(); $pop->connect($this->Host); if (!$pop) return false; if ($user && $pass) $esito=$pop->login($user,$pass); ELSE $esito=$pop->login($this->Username,$this->Password); if (!$esito) return false; $stato=$pop->get_office_status(); for ($i=1;$i<$stato['count_mails'];$i++) { echo implode("\n",$pop->get_top($i)); echo "\n------------------------------------------\n"; } $pop->close(); } */ /** @ignore */ function IncorporaImmagini($tags=array('link'=>'href','img'=>'src'),$txt='') { if (!$txt) $txt=$this->Body; try{ foreach ($tags as $tag=>$par) { if(preg_match_all('/<'.$tag.' ([^>]*)'.$par.'\s*=\s*[\'"](.*?)[\'"]([^>]*)>/iSx',$txt,$elementi) && is_array($elementi[2])) foreach ($elementi[2] as $i=>$im) if ($id=$this->embedElement($im)) $txt=str_replace($elementi[0][$i],"<$tag {$elementi[1][$i]} $par='$id' {$elementi[3][$i]}>", $txt); } if (preg_match_all('/<([^>]*)url[\(\'|\("|\(](.*?)[\'\)|"\)|\)]([^>]*)>/ix',$txt,$elementi) && is_array($elementi[2])) foreach ($elementi[2] as $i=>$im) if ($id=$this->embedElement($im)) $txt=str_replace($elementi[0][$i],"<{$elementi[1][$i]}url({$im}){$elementi[3][$i]}>", $txt); $this->Set_Testo($txt); } catch (Exception $e) {} return $txt; } } ?>