id_caddie_empr = $id_caddie_empr; } function send($objet_mail, $message, $paquet_envoi=0) { global $charset, $msg; global $pmb_mail_html_format, $pmb_img_url, $pmb_img_folder; global $PMBuserprenom, $PMBusernom, $PMBuseremail, $PMBuseremailbcc; if ($this->id_caddie_empr) { // ajouter les tags si besoin : if (strpos("",substr($message,0,20))===false) $message="$message"; $headers = "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=iso-8859-1"; if (!$this->total) { $sql = "select 1 from empr_caddie_content where (flag='' or flag is null or flag=2) and empr_caddie_id=".$this->id_caddie_empr; $sql_result = mysql_query($sql) or die ("Couldn't select count(*) mailing table $sql"); $this->total=mysql_num_rows($sql_result); } $sql = "select *, date_format(empr_date_adhesion, '".$msg["format_date"]."') as aff_empr_date_adhesion, date_format(empr_date_expiration, '".$msg["format_date"]."') as aff_empr_date_expiration from empr, empr_caddie_content where (flag='' or flag is null) and empr_caddie_id=".$this->id_caddie_empr." and object_id=id_empr "; if ($paquet_envoi) $sql .= " limit 0,$paquet_envoi "; $sql_result = mysql_query($sql) or die ("Couldn't select empr table !"); $n_envoi=mysql_num_rows($sql_result); $ienvoi=0; $this->envoi_KO=0; while ($ienvoi<$n_envoi) { $destinataire=mysql_fetch_object($sql_result); $iddest=$destinataire->id_empr; $emaildest=$destinataire->empr_mail; $nomdest=$destinataire->empr_nom; if ($destinataire->empr_prenom) $nomdest=$destinataire->empr_prenom." ".$destinataire->empr_nom; $message_to_send = $message; $message_to_send=str_replace("!!empr_name!!", $destinataire->empr_nom,$message_to_send); $message_to_send=str_replace("!!empr_first_name!!", $destinataire->empr_prenom,$message_to_send); $message_to_send=str_replace("!!empr_login!!", $destinataire->empr_login,$message_to_send); $message_to_send=str_replace("!!empr_password!!", $destinataire->empr_password,$message_to_send); $message_to_send=str_replace("!!empr_mail!!", $destinataire->empr_mail,$message_to_send); if (strpos($message_to_send,"!!empr_loans!!")) $message_to_send=str_replace("!!empr_loans!!", m_liste_prets($destinataire),$message_to_send); if (strpos($message_to_send,"!!empr_resas!!")) $message_to_send=str_replace("!!empr_resas!!", m_liste_resas($destinataire),$message_to_send); if (strpos($message_to_send,"!!empr_name_and_adress!!")) $message_to_send=str_replace("!!empr_name_and_adress!!", nl2br(m_lecteur_adresse($destinataire)),$message_to_send); if (strpos($message_to_send,"!!empr_all_information!!")) $message_to_send=str_replace("!!empr_all_information!!", nl2br(m_lecteur_info($destinataire)),$message_to_send); //générer le corps du message if ($pmb_mail_html_format==2){ // transformation des url des images pmb en chemin absolu ( a cause de tinyMCE ) preg_match_all("/(src|background)=\"(.*)\"/Ui", $message_to_send, $images); if(isset($images[2])) { foreach($images[2] as $i => $url) { $filename = basename($url); $directory = dirname($url); if(urldecode($directory."/")==$pmb_img_url){ $newlink=$pmb_img_folder .$filename; $message_to_send = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$newlink."\"", $message_to_send); } } } } $envoi_OK = mailpmb($nomdest, $emaildest, $objet_mail, $message_to_send, $PMBuserprenom." ".$PMBusernom, $PMBuseremail, $headers, "", $PMBuseremailbcc) ; if ($envoi_OK) { mysql_query("update empr_caddie_content set flag='1' where object_id='".$iddest."' and empr_caddie_id=".$this->id_caddie_empr) or die ("Couldn't update empr_caddie_content !"); } else { mysql_query("update empr_caddie_content set flag='2' where object_id='".$iddest."' and empr_caddie_id=".$this->id_caddie_empr) or die ("Couldn't update empr_caddie_content !"); $this->envoi_KO++; } $ienvoi++; } $this->total_envoyes=(($this->total_envoyes+$ienvoi)*1)-$this->envoi_KO; } } } //mailing_empr class end