/** * @author Gianluca GIMIGLIANO */ /** * @ignore */ include_once(dirname(__FILE__)."/phpmailer/class.phpmailer.php"); /* include_once(dirname(__FILE__)."/mypop3/pop3.class.inc"); */ /** * Questa classe permette la costruzione facilitata di mail da inviare, basato su PHPMailer * @access public * @package myMail */ class myMail extends PHPMailer { /**#@+ @ignore */ var $LastId; var $NEmbedded; var $Priority = 3; //Email priority (1 = High, 3 = Normal, 5 = low). var $CharSet = "iso-8859-1"; var $ContentType = "text/plain"; var $Encoding = "8bit"; var $ErrorInfo = ""; var $From = "root@localhost"; var $FromName = "Root User"; var $Sender = ""; // email (Return-Path) var $Subject = ""; var $Body = ""; var $AltBody = ""; var $WordWrap = 0; var $Mailer = "smtp"; var $Sendmail = ""; var $PluginDir = ""; var $Version = "1.73"; var $ConfirmReadingTo = ""; var $Hostname = ""; /**#@-*/ /** * Costruttore * @param string $nome_mittente Nome descrittivo del mittente * @param string $email_mittente Email del mittente * @param string|array $email_destinatari L'email del destinatario o un array con tutte le mail o un array associativo che associa "email Destinatario"=>"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('~([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("#