Accueil > > > CLASS D' ENVOIE DE MAIL EN SMTP
CLASS D' ENVOIE DE MAIL EN SMTP
Information sur la source
Description
Voilà une class SMTP assez complete. - Possibilité de s' indentifier - Possibilité de rentrer les entêtes(header) manuelement - Possibilité de maintenir la conntection smtp - Possibilité d' ajouter des pièces jointes - Possibilité du choix de l' encodage Types de champs supportés : - To - Cc - Bcc En version simple, le code d' envoie fait 3 lignes !!! La version Anglaise est disponible. (traduction faite par Pierre CORBEL : http://www.some-ideas.net/ )
Source
- <?php
- /*******************************************************************************
- *
- * Nom de la source :
- * Class SMTP
- * Nom du fichier par défaut :
- * Class.SMTP.php
- * Auteur :
- * Nuel Guillaume alias Immortal-PC
- * Site Web :
- * http://immortal-pc.info/
- *
- *******************************************************************************/
-
- class SMTP {
- // Nom du domaine ou nom du serveur
- var $NomDuDomaine = '';
-
- // De Qui
- var $From = 'root@localhost';// Adresse de l' expéditeur
- var $FromName = 'Root';// Nom de l' expéditeur
- var $ReplyTo = 'root@localhost';// Adresse de retour
- var $org = 'Localhost'; // Organisation
-
- // A Qui
- var $To = '';
- // Utilisation : $Bcc = 'mail1,mail2,....';
- var $Bcc = '';// Blind Carbon Copy, c'est à dire que les adresses qui sont contenue ici seront invisibles pour tout le monde
- var $Cc = '';
-
- // Priorité
- var $Priority = 3;// Priorité accordée au mail (valeur allant de 1 pour Urgent à 3 pour normal et 6 pour bas)
-
- // Encodage
- var $ContentType = 'html';//Contenu du mail (texte, html...) (txt , html, txt/html)
- var $Encoding = '8bit'; // Ancienne valeur quoted-printable
- var $ISO = 'iso-8859-15';
- var $MIME = '1.0';// La version mime
- var $Encode = false;// Encodage necessaire ou pas
- var $CHARSET = '';
-
- // Confirmation de reception
- var $Confimation_reception = '';// Entrez l' adresse où sera renvoyé la confirmation
-
- // Le mail
- var $Sujet = '';
- var $Body = '';
- var $Body_txt = '';
-
- // Fichier(s) joint(s)
- var $File_joint = array();
-
- // Nombre tour
- var $Tour = 0;
-
-
- //**************************************************************************
- // Paramètre de connection SMTP
- //**************************************************************************
- var $Authentification_smtp = false;
-
- var $serveur = '';// Serveur SMTP
- var $port = 25;// Port SMTP
- var $login_smtp = '';// Login pour le serveur SMTP
- var $mdp_smtp = '';// Mot de passe pour le serveur SMTP
- var $time_out = 10;// Durée de la connection avec le serveur SMTP
- var $tls = false;// Activation de la connection sécurisée (anciennement ssl)
-
-
- //**************************************************************************
- // Variables temporaires
- //**************************************************************************
- var $smtp_connection = '';// Variable de connection
- var $erreur = '';
- var $debug = false;
-
- //------------------------------------------------------------------------------
-
- //**************************************************************************
- // Fonction de déclaration de connection SMTP
- //**************************************************************************
- function SMTP($serveur='', $user='', $pass='', $port=25, $NomDuDomaine='', $debug=false){
- if($serveur){
- $this->serveur = $serveur;
- }
- if($user){
- $this->Authentification_smtp = true;
- $this->login_smtp = $user;
- $this->mdp_smtp = $pass;
- }
- $this->port = $port;
- if($NomDuDomaine){
- $this->NomDuDomaine = $NomDuDomaine;
- }
- $this->debug = $debug;
- }
-
-
- //**************************************************************************
- // Fonction de connection SMTP
- //**************************************************************************
- function Connect_SMTP(){
- // Definition du charset
- if(!$this->CHARSET){ $this->CHARSET = mb_internal_encoding(); }
-
- // Connection au serveur SMTP
- $this->smtp_connection = fsockopen($this->serveur, // Serveur
- $this->port, // Port de connection
- $num_erreur, // Numéros de l' erreur
- $msg_erreur, // Message d' erreur
- $this->time_out); // Durée de la connection en secs
- if(!$this->smtp_connection){// Vérification de la connection
- $this->erreur = 'Impossible de se connecter au serveur SMTP !!!<br />'."\r\n"
- .'Numéro de l' erreur: '.$num_erreur.'<br />'."\r\n"
- .'Message renvoyé: '.$msg_erreur.'<br />'."\r\n";
- return false;
- }
-
- // Suppression du message d' accueil
- $reponce = $this->get_smtp_data();
- // Debug
- if($this->debug){
- echo '<div style="color:#993300;">Connection</div>',"\r\n",str_replace("\r\n", '<br />', $reponce['msg']);
- }
-
- // On règle le timeout du serveur SMTP car parfois, le serveur SMTP peut être un peut lent à répondre
- // Windows ne comprend pas la fonction socket_set_timeout donc on vérifi que l' on travail sous Linux
- if(substr(PHP_OS, 0, 3) !== 'WIN'){
- socket_set_timeout($this->smtp_connection, $this->time_out, 0);
- }
-
- //**********************************************************************
- // Commande EHLO et HELO
- if($this->NomDuDomaine === ''){// On vérifit si le nom de domaine à été renseigné
- if($_SERVER['SERVER_NAME'] !== ''){
- $this->NomDuDomaine = $_SERVER['SERVER_NAME'];
- }else{
- $this->NomDuDomaine = 'localhost.localdomain';
- }
- }
-
- if(!$this->Commande('EHLO '.$this->NomDuDomaine, 250)){// Commande EHLO
- // Deusième commande EHLO -> HELO
- if(!$this->Commande('HELO '.$this->NomDuDomaine, 250, 'Le serveur refuse l' authentification (EHLO et HELO) !!!')){// Commande HELO
- return false;
- }
- }
-
- if($this->tls && !$this->Commande('STARTTLS', 220, 'Le serveur refuse la connection sécurisée ( STARTTLS ) !!!')){// Commande STARTTLS
- return false;
- }
-
- if($this->Authentification_smtp){// On vérifi si l' on a besoin de s' authentifier
- //******************************************************************
- // Authentification
- //******************************************************************
- if(!$this->Commande('AUTH LOGIN', 334, 'Le serveur refuse l' authentification (AUTH LOGIN) !!!')){
- return false;
- }
-
-
- //******************************************************************
- // Authentification : Login
- //******************************************************************
- $tmp = $this->Commande(base64_encode($this->login_smtp), 334, 'Login ( Nom d' utilisateur ) incorrect !!!', 0);
- if(!$tmp['no_error']){
- return false;
- }
- // Debug
- if($this->debug){
- echo '<div style="color:#993300;">Envoie du login.</div>',"\r\n",str_replace("\r\n", '<br />', $tmp['msg']);
- }
-
-
- //******************************************************************
- // Authentification : Mot de passe
- //******************************************************************
- $tmp = $this->Commande(base64_encode($this->mdp_smtp), 235, 'Mot de passe incorrect !!!', 0);
- if(!$tmp['no_error']){
- return false;
- }
- // Debug
- if($this->debug){
- echo '<div style="color:#993300;">Envoie du mot de passe.</div>',"\r\n",str_replace("\r\n", '<br />', $tmp['msg']);
- }
-
- }
-
- //**********************************************************************
- // Connecté au serveur SMTP
- //**********************************************************************
- return true;
- }
-
-
- //**************************************************************************
- // Fonctons de set
- //**************************************************************************
- function set_from($name, $email='', $org='Localhost'){
- $this->FromName = $name;
- if($this->Encode){
- $this->FromName = $this->encode_mimeheader(mb_convert_encoding($this->FromName, $this->ISO, $this->CHARSET), $this->ISO);
- }
- if(!empty($email)){
- $this->From = $email;
- }
- $this->org = $org;
- unset($name, $email, $org);
- }
-
- function set_encode($ISO, $CHARSET=''){
- $this->Encode = true;
- $this->ISO = $ISO;
- $this->CHARSET = $CHARSET;
- unset($ISO, $CHARSET);
- }
-
-
- //**************************************************************************
- // System d' encodage par Pierre CORBEL
- //**************************************************************************
- function encode_mimeheader($string){
- $encoded = '';
- $CHARSET = mb_internal_encoding();
- // Each line must have length <= 75, including `=?'.$this->CHARSET.'?B?` and `?=`
- $length = 75 - strlen('=?'.$this->CHARSET.'?B?') - 2;
- $tmp = mb_strlen($string, $this->CHARSET);
- // Average multi-byte ratio
- $ratio = mb_strlen($string, $this->CHARSET) / strlen($string);
- // Base64 has a 4:3 ratio
- $magic = floor(3 * $length * $ratio / 4);
- $avglength = $magic;
-
- for($i=0; $i <= $tmp; $i+=$magic) {
- $magic = $avglength;
- $offset = 0;
- // Recalculate magic for each line to be 100% sure
- do{
- $magic -= $offset;
- $chunk = mb_substr($string, $i, $magic, $this->CHARSET);
- $chunk = base64_encode($chunk);
- $offset++;
- }while(strlen($chunk) > $length);
- if($chunk){
- $encoded .= ' '.'=?'.$this->CHARSET.'?B?'.$chunk.'?='."\r\n";
- }
- }
- // Chomp the first space and the last linefeed
- return substr($encoded, 1, -2);
- }
-
-
- //**************************************************************************
- // Foncton d' ajout de pièce jointe
- //**************************************************************************
- function add_file($url_file){
- if(!$url_file){
- $this->erreur = 'Champs manquant !!!<br />'."\r\n";
- return false;
- }
- if(!($fp = @fopen($url_file, 'a'))){
- $this->erreur = 'Fichier introuvable !!!<br />'."\r\n";
- return false;
- }
- fclose($fp);
-
- $file_name = explode('/', $url_file);
- $file_name = $file_name[count($file_name)-1];
- $mime = parse_ini_file('./mime.ini');
- $ext = explode('.', $file_name);
- $ext = $ext[count($ext)-1];
-
- if(IsSet($this->File_joint[$file_name])){
- $file_name = explode('_', str_replace('.'.$ext, '', $file_name));
- if(is_numeric($file_name[count($file_name)-1])){
- $file_name[count($file_name)-1]++;
- $file_name = implode('_', $file_name);
- }else{
- $file_name = implode('_', $file_name);
- $file_name .= '_1';
- }
- $file_name .= '.'.$ext;
- }
- $this->File_joint[$file_name] = array(
- 'url' => $url_file,
- 'mime' => $mime[$ext]
- );
- unset($file_name, $mime, $ext);
- }
-
-
- //**************************************************************************
- // Entêtes (Headers)
- //**************************************************************************
- function headers(){
- // Id unique
- $Boundary1 = '------------Boundary-00=_'.substr(md5(uniqid(time())), 0, 7).'0000000000000';
- $Boundary2 = '------------Boundary-00=_'.substr(md5(uniqid(time())), 0, 7).'0000000000000';
- $Boundary3 = '------------Boundary-00=_'.substr(md5(uniqid(time())), 0, 7).'0000000000000';
-
- $header = '';
- $No_body = 0;
-
- // Adresse de l'expéditeur (format : Nom <adresse_mail>)
- if(!empty($this->From)){
- $header .= 'X-Sender: '.$this->From."\n";// Adresse réelle de l'expéditeur
- }
- // La version mime
- if(!empty($this->MIME)){
- $header .= 'MIME-Version: '.$this->MIME."\n";
- }
- $header .= sprintf("Message-ID: <%s@%s>%s", md5(uniqid(time())), $this->NomDuDomaine, "\n")
- .'Date: '.date('r')."\n"
- .'Content-Type: Multipart/Mixed;'."\n"
- .' boundary="'.$Boundary1.'"'."\n"
- // Logiciel utilisé pour l' envoi des mails
- .'X-Mailer: PHP '.phpversion()."\n";
- // Adresse de l'expéditeur (format : Nom <adresse_mail>)
- if(!empty($this->From)){
- if(!empty($this->FromName)){
- $header .= 'From: "'.$this->FromName.'"';
- }else{
- $header .= 'From: ';
- }
- $header .= '<'.$this->From.">\n";
- }
- $header .= 'X-FID: FLAVOR00-NONE-0000-0000-000000000000'."\n";
-
- // Priorité accordée au mail (valeur allant de 1 pour Urgent à 3 pour normal et 6 pour bas)
- if(!empty($this->Priority)){
- $header .= 'X-Priority: '.$this->Priority."\n";
- }
- // To
- if(!empty($this->To)){// A
- $header .= 'To: '.$this->To."\n";
- }else{
- $No_body++;// Personne
- }
- // Cc
- if(!empty($this->Cc)){// Copie du mail
- $header .= 'Cc: '.$this->Cc."\n";
- }else{
- $No_body++;// Personne
- }
- // Bcc
- if(empty($this->Bcc)){// Blind Carbon Copy, c' est à dire que les adresses qui sont contenue ici seront invisibles pour tout le monde
- $No_body++;// Personne
- }
- // Sujet
- if(!empty($this->Sujet)){
- $header .= 'Subject: '.$this->Sujet."\n";
- }
- if(!empty($this->Confimation_reception)){// Adresse utilisée pour la réponse au mail
- $header .= 'Disposition-Notification-To: <'.$this->Confimation_reception.'>'."\n";
- }
- // ReplyTo
- if(!empty($this->ReplyTo) && $this->ReplyTo !== $this->From && $this->ReplyTo !== 'root@localhost'){// Adresse utilisée pour la réponse au mail
- $header .= 'Reply-to: '.$this->ReplyTo."\n"
- .'Return-Path: <'.$this->ReplyTo.">\n";
- }
- if(!IsSet($_SERVER['REMOTE_ADDR'])){$_SERVER['REMOTE_ADDR'] = '127.0.0.1';}
- if(!IsSet($_SERVER['HTTP_X_FORWARDED_FOR'])){$_SERVER['HTTP_X_FORWARDED_FOR'] = '';}
- if(!IsSet($_SERVER['HTTP_USER_AGENT'])){$_SERVER['HTTP_USER_AGENT'] = 'Internet Explorer';}
- if(!IsSet($_SERVER['HTTP_ACCEPT_LANGUAGE'])){$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'Fr-fr';}
- $host = 'localhost';
- if(function_exists('gethostbyaddr') && $_SERVER['REMOTE_ADDR'] !== '127.0.0.1'){$host = gethostbyaddr($_SERVER['REMOTE_ADDR']);}
- $header .= 'X-Client-IP: '.$_SERVER['REMOTE_ADDR']."\n"
- .'X-Client-PROXY: '.$_SERVER['HTTP_X_FORWARDED_FOR']."\n"
- .'X-Client-Agent: '.$_SERVER['HTTP_USER_AGENT']."\n"
- .'X-Client-Host: '.$host."\n"
- .'X-Client-Language: '.$_SERVER['HTTP_ACCEPT_LANGUAGE']."\n"
- .'Organization: '.$this->org."\n"
- ."\n\n\n"
- .'--'.$Boundary1."\n"
- .'Content-Type: Multipart/Alternative;'."\n"
- .' boundary="'.$Boundary3.'"'."\n"
- ."\n\n"
- .'--'.$Boundary3."\n";
- if($this->ContentType === 'txt' || $this->ContentType === 'txt/html'){
- $header .= 'Content-Type: Text/Plain;'."\r\n"
- .' charset="'.$this->ISO.'"'."\r\n"
- .'Content-Transfer-Encoding: '.$this->Encoding."\r\n"
- ."\r\n";
- if($this->ContentType === 'txt'){
- $header .= $this->Body."\r\n";
- }else{
- $header .= $this->Body_txt."\r\n";
- }
- }elseif($this->ContentType === 'html' || $this->ContentType === 'txt/html'){
- if($this->ContentType === 'txt/html'){
- $header .= '--'.$Boundary3."\r\n";
- }
- $header .= 'Content-Type: Text/HTML;'."\r\n"
- .' charset="'.$this->ISO.'"'."\r\n"
- .'Content-Transfer-Encoding: '.$this->Encoding."\r\n"
- ."\r\n"
- .'<html><head>'."\r\n"
- .'<meta http-equiv="Content-LANGUAGE" content="French" />'."\r\n"
- .'<meta http-equiv="Content-Type" content="text/html; charset='.$this->ISO.'" />'."\r\n"
- .'</head>'."\r\n"
- .'<body>'."\r\n"
- .$this->Body."\r\n"
- .'</body></html>'."\r\n"
- .'--'.$Boundary3.'--'."\r\n";
- }else{
- $header .= 'Content-Type: '.$this->ContentType.';'."\r\n"
- .' charset="'.$this->ISO.'"'."\r\n"
- .'Content-Transfer-Encoding: '.$this->Encoding."\r\n"
- ."\r\n"
- .$this->Body."\r\n";
- }
- $header .= "\n";
-
- // On joint le ou les fichiers
- if($this->File_joint){
- foreach($this->File_joint as $file_name => $file){
- $header .= '--'.$Boundary1."\n"
- .'Content-Type: '.$file['mime'].';'."\n"
- .' name="'.$file_name.'"'."\n"
- .'Content-Disposition: attachment'."\n"
- .'Content-Transfer-Encoding: base64'."\n"
- ."\n"
- .chunk_split(base64_encode(file_get_contents($file['url'])))."\n"
- ."\n\n";
- }
- }
- $header .= '--'.$Boundary1.'--';
-
- if($No_body === 3){
- $this->erreur = 'Le mail n' a pas de destinataire !!!';
- return false;
- }
- return $header;
- }
-
-
- //**************************************************************************
- // Envoie du mail avec le serveur SMTP
- //**************************************************************************
- function smtp_mail($to, $subject, $message, $header=''){
- // Pas de déconnection automatique
- $auto_disconnect = false;
- // On vérifit si la connection existe
- if(empty($this->smtp_connection)){
- if(!$this->Connect_SMTP()){// Connection
- $this->erreur .= 'Impossible d' envoyer le mail !!!<br />'."\r\n";
- return false;
- }
- $auto_disconnect = true;// Déconnection automatique activée
- }
-
- // On vérifit Que c' est le premier tour sinon on éfface les anciens paramètres
- if($this->Tour){
- if($this->Commande('RSET', 250, 'Envoie du mail impossible !!!')){
- $this->Tour = 0;
- }
- }
-
- //**********************************************************************
- // Variables temporairement modifiées
- if(!empty($to)){
- $this->To = $to;
- }
- if(!empty($subject)){
- if($this->Encode){
- $this->Sujet = $this->encode_mimeheader(mb_convert_encoding($subject, $this->ISO, $this->CHARSET), $this->ISO);
- }else{
- $this->Sujet = mb_encode_mimeheader($subject, $this->ISO);
- }
- }
-
- if(is_array($message)){
- $this->Body = $message[0];
- $this->Body_txt = $message[1];
- if($this->Encode){
- $this->Body = mb_convert_encoding($this->Body, $this->ISO, $this->CHARSET);
- $this->Body_txt = mb_convert_encoding($this->Body_txt, $this->ISO, $this->CHARSET);
- }
- }else{
- $this->Body = $message;
- if($this->Encode){
- $this->Body = mb_convert_encoding($this->Body, $this->ISO, $this->CHARSET);
- }
- }
-
- //**********************************************************************
- // Y a t' il un destinataire
- if(empty($this->To) && empty($header) && empty($this->Bcc) && empty($this->Cc)){
- $this->erreur = 'Veuillez entrer une adresse de destination !!!<br />'."\r\n";
- return false;
- }
-
- //**********************************************************************
- // Envoie des informations
- //**********************************************************************
-
- //**********************************************************************
- // De Qui
- if(!empty($this->From) && !$this->Tour){
- if(!$this->Commande('MAIL FROM:<'.$this->From.'>', 250, 'Envoie du mail impossible car le serveur n' accèpte pas la commande MAIL FROM !!!')){
- return false;
- }
- $this->Tour = 1;
- }
-
- //**********************************************************************
- // A Qui
- $A = array();
- if(!empty($this->To)){
- $A[0] = $this->To;
- }
- if(!empty($this->Bcc)){
- $A[1] = $this->Bcc;
- }
- if(!empty($this->Cc)){
- $A[2] = $this->Cc;
- }
- foreach($A as $cle => $tmp_to){
- if(substr_count($tmp_to, ',')){
- $tmp_to = explode(',', $tmp_to);
- foreach($tmp_to as $cle => $tmp_A){
- if(!$this->Commande('RCPT TO:<'.$tmp_A.'>', array(250,251), 'Envoie du mail impossible car le serveur n' accèpte pas la commande RCPT TO !!!')){
- return false;
- }
- }
- }else{
- if(!$this->Commande('RCPT TO:<'.$tmp_to.'>', array(250,251), 'Envoie du mail impossible car le serveur n' accèpte pas la commande RCPT TO !!!')){
- return false;
- }
- }
- }
-
- //**********************************************************************
- // On créer les entêtes ( headers ) si c' est pas fait
- if(empty($header)){
- if(!$header = $this->headers()){
- $this->erreur .= 'Impossible d' envoyer le mail !!!<br />'."\r\n";
- return false;
- }
- }
-
-
- //**********************************************************************
- // On indique que l' on va envoyer des données
- if(!$this->Commande('DATA', 354, 'Envoie du mail impossible car le serveur n' accèpte pas la commande DATA!!!')){
- return false;
- }
-
-
- //**********************************************************************
- // Envoie de l' entête et du message
- fputs($this->smtp_connection, $header);
- fputs($this->smtp_connection, "\r\n.\r\n");
-
- $reponce = $this->get_smtp_data();
- // Debug
- if($this->debug){
- echo '<div style="color:#993300;">Entête et message :<br />',"\r\n",'<div style="padding-left:25px;">',str_replace(array("\r\n","\n"), '<br />', $header),'<br />',"\r\n",$message,'</div>',"\r\n",'</div>',"\r\n",str_replace("\r\n", '<br />', $reponce['msg']);
- }
- if($reponce['code'] !== 250 && $reponce['code'] !== 354){
- $this->erreur = 'Envoie du mail impossible !!!<br />'."\r\n"
- .'Numéro de l' erreur: '.$reponce['code'].'<br />'."\r\n"
- .'Message renvoyé: '.$reponce['msg'].'<br />'."\r\n";
- return false;
- }
-
-
- //**********************************************************************
- // Variables temporairement modifiées
- if($to === $this->To){
- $this->To = '';
- }
- if($subject === $this->Sujet){
- $this->Sujet = '';
- }
-
- //**********************************************************************
- // Déconnection automatique
- //**********************************************************************
- if($auto_disconnect){// Auto déconnection ?
- $this->Deconnection_SMTP();// Déconnection
- }
-
- //**********************************************************************
- // Mail envoyé
- //**********************************************************************
- return true;
- }
-
-
- //**************************************************************************
- // Lecture des données renvoyées par le serveur SMTP
- //**************************************************************************
- function get_smtp_data(){
- $data = '';
- while($donnees = fgets($this->smtp_connection, 515)){// On parcour les données renvoyées
- $data .= $donnees;
-
- if(substr($donnees,3,1) == ' ' && !empty($data)){break;}// On vérifi si on a toutes les données
- }
- // Renvoie des données : array(Code, message complet)
- return array('code'=>(int)substr($data, 0, 3), 'msg'=>$data);
- }
-
-
- //**************************************************************************
- // Execution des commandes SMTP
- //**************************************************************************
- function Commande($commande, $bad_error, $msg_error='', $debug=1){
- if(!empty($this->smtp_connection)){
- fputs($this->smtp_connection, $commande."\n");
- $reponce = $this->get_smtp_data();
- // Debug
- if($this->debug && $debug){
- echo '<div style="color:#993300;">',htmlentities($commande),'</div>',"\r\n",str_replace("\r\n", '<br />', $reponce['msg']);
- }
-
- // Tableau de code valide
- if((is_array($bad_error) && !in_array($reponce['code'], $bad_error)) || (!is_array($bad_error) && $reponce['code'] !== $bad_error)){
- if($msg_error){
- $this->erreur = $msg_error.'<br />'."\r\n"
- .'Numéro de l' erreur: '.$reponce['code'].'<br />'."\r\n"
- .'Message renvoyé: '.$reponce['msg'].'<br />'."\r\n";
- }
- if(!$debug){
- return array('no_error'=>false, 'msg'=>$reponce['msg']);
- }else{
- return false;
- }
- }
-
- if(!$debug){
- return array('no_error'=>true, 'msg'=>$reponce['msg']);
- }else{
- return true;
- }
- }else{
- $this->erreur = 'Impossible d' éxecuter la commande <span style="font-weight:bolder;">'.$commande.'</span> car il n' y a pas de connection !!!<br />'."\r\n";
- if(!$debug){
- return array('no_error'=>false, 'msg'=>'');
- }else{
- return false;
- }
- }
- }
-
-
- //**************************************************************************
- // Fonction de déconnection SMTP
- //**************************************************************************
- function Deconnection_SMTP(){
- if(!empty($this->smtp_connection)){
- if(!$this->Commande('QUIT', 221, 'Impossible de se déconnecter !!!')){
- return false;
- }
-
- @sleep(5);// On laisse 5 seconde au serveur pour terminer toutes les instructions
- if(!fclose($this->smtp_connection)){
- $this->erreur = 'Impossible de se déconnecter !!!<br />'."\r\n";
- return false;
- }
- $this->smtp_connection = 0;
- return true;
- }
- $this->erreur = 'Impossible de se déconnecter car il n' y a pas de connection !!!<br />'."\r\n";
- return false;
- }
- }
- ?>
<?php
/*******************************************************************************
*
* Nom de la source :
* Class SMTP
* Nom du fichier par défaut :
* Class.SMTP.php
* Auteur :
* Nuel Guillaume alias Immortal-PC
* Site Web :
* http://immortal-pc.info/
*
*******************************************************************************/
class SMTP {
// Nom du domaine ou nom du serveur
var $NomDuDomaine = '';
// De Qui
var $From = 'root@localhost';// Adresse de l' expéditeur
var $FromName = 'Root';// Nom de l' expéditeur
var $ReplyTo = 'root@localhost';// Adresse de retour
var $org = 'Localhost'; // Organisation
// A Qui
var $To = '';
// Utilisation : $Bcc = 'mail1,mail2,....';
var $Bcc = '';// Blind Carbon Copy, c'est à dire que les adresses qui sont contenue ici seront invisibles pour tout le monde
var $Cc = '';
// Priorité
var $Priority = 3;// Priorité accordée au mail (valeur allant de 1 pour Urgent à 3 pour normal et 6 pour bas)
// Encodage
var $ContentType = 'html';//Contenu du mail (texte, html...) (txt , html, txt/html)
var $Encoding = '8bit'; // Ancienne valeur quoted-printable
var $ISO = 'iso-8859-15';
var $MIME = '1.0';// La version mime
var $Encode = false;// Encodage necessaire ou pas
var $CHARSET = '';
// Confirmation de reception
var $Confimation_reception = '';// Entrez l' adresse où sera renvoyé la confirmation
// Le mail
var $Sujet = '';
var $Body = '';
var $Body_txt = '';
// Fichier(s) joint(s)
var $File_joint = array();
// Nombre tour
var $Tour = 0;
//**************************************************************************
// Paramètre de connection SMTP
//**************************************************************************
var $Authentification_smtp = false;
var $serveur = '';// Serveur SMTP
var $port = 25;// Port SMTP
var $login_smtp = '';// Login pour le serveur SMTP
var $mdp_smtp = '';// Mot de passe pour le serveur SMTP
var $time_out = 10;// Durée de la connection avec le serveur SMTP
var $tls = false;// Activation de la connection sécurisée (anciennement ssl)
//**************************************************************************
// Variables temporaires
//**************************************************************************
var $smtp_connection = '';// Variable de connection
var $erreur = '';
var $debug = false;
//------------------------------------------------------------------------------
//**************************************************************************
// Fonction de déclaration de connection SMTP
//**************************************************************************
function SMTP($serveur='', $user='', $pass='', $port=25, $NomDuDomaine='', $debug=false){
if($serveur){
$this->serveur = $serveur;
}
if($user){
$this->Authentification_smtp = true;
$this->login_smtp = $user;
$this->mdp_smtp = $pass;
}
$this->port = $port;
if($NomDuDomaine){
$this->NomDuDomaine = $NomDuDomaine;
}
$this->debug = $debug;
}
//**************************************************************************
// Fonction de connection SMTP
//**************************************************************************
function Connect_SMTP(){
// Definition du charset
if(!$this->CHARSET){ $this->CHARSET = mb_internal_encoding(); }
// Connection au serveur SMTP
$this->smtp_connection = fsockopen($this->serveur, // Serveur
$this->port, // Port de connection
$num_erreur, // Numéros de l' erreur
$msg_erreur, // Message d' erreur
$this->time_out); // Durée de la connection en secs
if(!$this->smtp_connection){// Vérification de la connection
$this->erreur = 'Impossible de se connecter au serveur SMTP !!!<br />'."\r\n"
.'Numéro de l' erreur: '.$num_erreur.'<br />'."\r\n"
.'Message renvoyé: '.$msg_erreur.'<br />'."\r\n";
return false;
}
// Suppression du message d' accueil
$reponce = $this->get_smtp_data();
// Debug
if($this->debug){
echo '<div style="color:#993300;">Connection</div>',"\r\n",str_replace("\r\n", '<br />', $reponce['msg']);
}
// On règle le timeout du serveur SMTP car parfois, le serveur SMTP peut être un peut lent à répondre
// Windows ne comprend pas la fonction socket_set_timeout donc on vérifi que l' on travail sous Linux
if(substr(PHP_OS, 0, 3) !== 'WIN'){
socket_set_timeout($this->smtp_connection, $this->time_out, 0);
}
//**********************************************************************
// Commande EHLO et HELO
if($this->NomDuDomaine === ''){// On vérifit si le nom de domaine à été renseigné
if($_SERVER['SERVER_NAME'] !== ''){
$this->NomDuDomaine = $_SERVER['SERVER_NAME'];
}else{
$this->NomDuDomaine = 'localhost.localdomain';
}
}
if(!$this->Commande('EHLO '.$this->NomDuDomaine, 250)){// Commande EHLO
// Deusième commande EHLO -> HELO
if(!$this->Commande('HELO '.$this->NomDuDomaine, 250, 'Le serveur refuse l' authentification (EHLO et HELO) !!!')){// Commande HELO
return false;
}
}
if($this->tls && !$this->Commande('STARTTLS', 220, 'Le serveur refuse la connection sécurisée ( STARTTLS ) !!!')){// Commande STARTTLS
return false;
}
if($this->Authentification_smtp){// On vérifi si l' on a besoin de s' authentifier
//******************************************************************
// Authentification
//******************************************************************
if(!$this->Commande('AUTH LOGIN', 334, 'Le serveur refuse l' authentification (AUTH LOGIN) !!!')){
return false;
}
//******************************************************************
// Authentification : Login
//******************************************************************
$tmp = $this->Commande(base64_encode($this->login_smtp), 334, 'Login ( Nom d' utilisateur ) incorrect !!!', 0);
if(!$tmp['no_error']){
return false;
}
// Debug
if($this->debug){
echo '<div style="color:#993300;">Envoie du login.</div>',"\r\n",str_replace("\r\n", '<br />', $tmp['msg']);
}
//******************************************************************
// Authentification : Mot de passe
//******************************************************************
$tmp = $this->Commande(base64_encode($this->mdp_smtp), 235, 'Mot de passe incorrect !!!', 0);
if(!$tmp['no_error']){
return false;
}
// Debug
if($this->debug){
echo '<div style="color:#993300;">Envoie du mot de passe.</div>',"\r\n",str_replace("\r\n", '<br />', $tmp['msg']);
}
}
//**********************************************************************
// Connecté au serveur SMTP
//**********************************************************************
return true;
}
//**************************************************************************
// Fonctons de set
//**************************************************************************
function set_from($name, $email='', $org='Localhost'){
$this->FromName = $name;
if($this->Encode){
$this->FromName = $this->encode_mimeheader(mb_convert_encoding($this->FromName, $this->ISO, $this->CHARSET), $this->ISO);
}
if(!empty($email)){
$this->From = $email;
}
$this->org = $org;
unset($name, $email, $org);
}
function set_encode($ISO, $CHARSET=''){
$this->Encode = true;
$this->ISO = $ISO;
$this->CHARSET = $CHARSET;
unset($ISO, $CHARSET);
}
//**************************************************************************
// System d' encodage par Pierre CORBEL
//**************************************************************************
function encode_mimeheader($string){
$encoded = '';
$CHARSET = mb_internal_encoding();
// Each line must have length <= 75, including `=?'.$this->CHARSET.'?B?` and `?=`
$length = 75 - strlen('=?'.$this->CHARSET.'?B?') - 2;
$tmp = mb_strlen($string, $this->CHARSET);
// Average multi-byte ratio
$ratio = mb_strlen($string, $this->CHARSET) / strlen($string);
// Base64 has a 4:3 ratio
$magic = floor(3 * $length * $ratio / 4);
$avglength = $magic;
for($i=0; $i <= $tmp; $i+=$magic) {
$magic = $avglength;
$offset = 0;
// Recalculate magic for each line to be 100% sure
do{
$magic -= $offset;
$chunk = mb_substr($string, $i, $magic, $this->CHARSET);
$chunk = base64_encode($chunk);
$offset++;
}while(strlen($chunk) > $length);
if($chunk){
$encoded .= ' '.'=?'.$this->CHARSET.'?B?'.$chunk.'?='."\r\n";
}
}
// Chomp the first space and the last linefeed
return substr($encoded, 1, -2);
}
//**************************************************************************
// Foncton d' ajout de pièce jointe
//**************************************************************************
function add_file($url_file){
if(!$url_file){
$this->erreur = 'Champs manquant !!!<br />'."\r\n";
return false;
}
if(!($fp = @fopen($url_file, 'a'))){
$this->erreur = 'Fichier introuvable !!!<br />'."\r\n";
return false;
}
fclose($fp);
$file_name = explode('/', $url_file);
$file_name = $file_name[count($file_name)-1];
$mime = parse_ini_file('./mime.ini');
$ext = explode('.', $file_name);
$ext = $ext[count($ext)-1];
if(IsSet($this->File_joint[$file_name])){
$file_name = explode('_', str_replace('.'.$ext, '', $file_name));
if(is_numeric($file_name[count($file_name)-1])){
$file_name[count($file_name)-1]++;
$file_name = implode('_', $file_name);
}else{
$file_name = implode('_', $file_name);
$file_name .= '_1';
}
$file_name .= '.'.$ext;
}
$this->File_joint[$file_name] = array(
'url' => $url_file,
'mime' => $mime[$ext]
);
unset($file_name, $mime, $ext);
}
//**************************************************************************
// Entêtes (Headers)
//**************************************************************************
function headers(){
// Id unique
$Boundary1 = '------------Boundary-00=_'.substr(md5(uniqid(time())), 0, 7).'0000000000000';
$Boundary2 = '------------Boundary-00=_'.substr(md5(uniqid(time())), 0, 7).'0000000000000';
$Boundary3 = '------------Boundary-00=_'.substr(md5(uniqid(time())), 0, 7).'0000000000000';
$header = '';
$No_body = 0;
// Adresse de l'expéditeur (format : Nom <adresse_mail>)
if(!empty($this->From)){
$header .= 'X-Sender: '.$this->From."\n";// Adresse réelle de l'expéditeur
}
// La version mime
if(!empty($this->MIME)){
$header .= 'MIME-Version: '.$this->MIME."\n";
}
$header .= sprintf("Message-ID: <%s@%s>%s", md5(uniqid(time())), $this->NomDuDomaine, "\n")
.'Date: '.date('r')."\n"
.'Content-Type: Multipart/Mixed;'."\n"
.' boundary="'.$Boundary1.'"'."\n"
// Logiciel utilisé pour l' envoi des mails
.'X-Mailer: PHP '.phpversion()."\n";
// Adresse de l'expéditeur (format : Nom <adresse_mail>)
if(!empty($this->From)){
if(!empty($this->FromName)){
$header .= 'From: "'.$this->FromName.'"';
}else{
$header .= 'From: ';
}
$header .= '<'.$this->From.">\n";
}
$header .= 'X-FID: FLAVOR00-NONE-0000-0000-000000000000'."\n";
// Priorité accordée au mail (valeur allant de 1 pour Urgent à 3 pour normal et 6 pour bas)
if(!empty($this->Priority)){
$header .= 'X-Priority: '.$this->Priority."\n";
}
// To
if(!empty($this->To)){// A
$header .= 'To: '.$this->To."\n";
}else{
$No_body++;// Personne
}
// Cc
if(!empty($this->Cc)){// Copie du mail
$header .= 'Cc: '.$this->Cc."\n";
}else{
$No_body++;// Personne
}
// Bcc
if(empty($this->Bcc)){// Blind Carbon Copy, c' est à dire que les adresses qui sont contenue ici seront invisibles pour tout le monde
$No_body++;// Personne
}
// Sujet
if(!empty($this->Sujet)){
$header .= 'Subject: '.$this->Sujet."\n";
}
if(!empty($this->Confimation_reception)){// Adresse utilisée pour la réponse au mail
$header .= 'Disposition-Notification-To: <'.$this->Confimation_reception.'>'."\n";
}
// ReplyTo
if(!empty($this->ReplyTo) && $this->ReplyTo !== $this->From && $this->ReplyTo !== 'root@localhost'){// Adresse utilisée pour la réponse au mail
$header .= 'Reply-to: '.$this->ReplyTo."\n"
.'Return-Path: <'.$this->ReplyTo.">\n";
}
if(!IsSet($_SERVER['REMOTE_ADDR'])){$_SERVER['REMOTE_ADDR'] = '127.0.0.1';}
if(!IsSet($_SERVER['HTTP_X_FORWARDED_FOR'])){$_SERVER['HTTP_X_FORWARDED_FOR'] = '';}
if(!IsSet($_SERVER['HTTP_USER_AGENT'])){$_SERVER['HTTP_USER_AGENT'] = 'Internet Explorer';}
if(!IsSet($_SERVER['HTTP_ACCEPT_LANGUAGE'])){$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'Fr-fr';}
$host = 'localhost';
if(function_exists('gethostbyaddr') && $_SERVER['REMOTE_ADDR'] !== '127.0.0.1'){$host = gethostbyaddr($_SERVER['REMOTE_ADDR']);}
$header .= 'X-Client-IP: '.$_SERVER['REMOTE_ADDR']."\n"
.'X-Client-PROXY: '.$_SERVER['HTTP_X_FORWARDED_FOR']."\n"
.'X-Client-Agent: '.$_SERVER['HTTP_USER_AGENT']."\n"
.'X-Client-Host: '.$host."\n"
.'X-Client-Language: '.$_SERVER['HTTP_ACCEPT_LANGUAGE']."\n"
.'Organization: '.$this->org."\n"
."\n\n\n"
.'--'.$Boundary1."\n"
.'Content-Type: Multipart/Alternative;'."\n"
.' boundary="'.$Boundary3.'"'."\n"
."\n\n"
.'--'.$Boundary3."\n";
if($this->ContentType === 'txt' || $this->ContentType === 'txt/html'){
$header .= 'Content-Type: Text/Plain;'."\r\n"
.' charset="'.$this->ISO.'"'."\r\n"
.'Content-Transfer-Encoding: '.$this->Encoding."\r\n"
."\r\n";
if($this->ContentType === 'txt'){
$header .= $this->Body."\r\n";
}else{
$header .= $this->Body_txt."\r\n";
}
}elseif($this->ContentType === 'html' || $this->ContentType === 'txt/html'){
if($this->ContentType === 'txt/html'){
$header .= '--'.$Boundary3."\r\n";
}
$header .= 'Content-Type: Text/HTML;'."\r\n"
.' charset="'.$this->ISO.'"'."\r\n"
.'Content-Transfer-Encoding: '.$this->Encoding."\r\n"
."\r\n"
.'<html><head>'."\r\n"
.'<meta http-equiv="Content-LANGUAGE" content="French" />'."\r\n"
.'<meta http-equiv="Content-Type" content="text/html; charset='.$this->ISO.'" />'."\r\n"
.'</head>'."\r\n"
.'<body>'."\r\n"
.$this->Body."\r\n"
.'</body></html>'."\r\n"
.'--'.$Boundary3.'--'."\r\n";
}else{
$header .= 'Content-Type: '.$this->ContentType.';'."\r\n"
.' charset="'.$this->ISO.'"'."\r\n"
.'Content-Transfer-Encoding: '.$this->Encoding."\r\n"
."\r\n"
.$this->Body."\r\n";
}
$header .= "\n";
// On joint le ou les fichiers
if($this->File_joint){
foreach($this->File_joint as $file_name => $file){
$header .= '--'.$Boundary1."\n"
.'Content-Type: '.$file['mime'].';'."\n"
.' name="'.$file_name.'"'."\n"
.'Content-Disposition: attachment'."\n"
.'Content-Transfer-Encoding: base64'."\n"
."\n"
.chunk_split(base64_encode(file_get_contents($file['url'])))."\n"
."\n\n";
}
}
$header .= '--'.$Boundary1.'--';
if($No_body === 3){
$this->erreur = 'Le mail n' a pas de destinataire !!!';
return false;
}
return $header;
}
//**************************************************************************
// Envoie du mail avec le serveur SMTP
//**************************************************************************
function smtp_mail($to, $subject, $message, $header=''){
// Pas de déconnection automatique
$auto_disconnect = false;
// On vérifit si la connection existe
if(empty($this->smtp_connection)){
if(!$this->Connect_SMTP()){// Connection
$this->erreur .= 'Impossible d' envoyer le mail !!!<br />'."\r\n";
return false;
}
$auto_disconnect = true;// Déconnection automatique activée
}
// On vérifit Que c' est le premier tour sinon on éfface les anciens paramètres
if($this->Tour){
if($this->Commande('RSET', 250, 'Envoie du mail impossible !!!')){
$this->Tour = 0;
}
}
//**********************************************************************
// Variables temporairement modifiées
if(!empty($to)){
$this->To = $to;
}
if(!empty($subject)){
if($this->Encode){
$this->Sujet = $this->encode_mimeheader(mb_convert_encoding($subject, $this->ISO, $this->CHARSET), $this->ISO);
}else{
$this->Sujet = mb_encode_mimeheader($subject, $this->ISO);
}
}
if(is_array($message)){
$this->Body = $message[0];
$this->Body_txt = $message[1];
if($this->Encode){
$this->Body = mb_convert_encoding($this->Body, $this->ISO, $this->CHARSET);
$this->Body_txt = mb_convert_encoding($this->Body_txt, $this->ISO, $this->CHARSET);
}
}else{
$this->Body = $message;
if($this->Encode){
$this->Body = mb_convert_encoding($this->Body, $this->ISO, $this->CHARSET);
}
}
//**********************************************************************
// Y a t' il un destinataire
if(empty($this->To) && empty($header) && empty($this->Bcc) && empty($this->Cc)){
$this->erreur = 'Veuillez entrer une adresse de destination !!!<br />'."\r\n";
return false;
}
//**********************************************************************
// Envoie des informations
//**********************************************************************
//**********************************************************************
// De Qui
if(!empty($this->From) && !$this->Tour){
if(!$this->Commande('MAIL FROM:<'.$this->From.'>', 250, 'Envoie du mail impossible car le serveur n' accèpte pas la commande MAIL FROM !!!')){
return false;
}
$this->Tour = 1;
}
//**********************************************************************
// A Qui
$A = array();
if(!empty($this->To)){
$A[0] = $this->To;
}
if(!empty($this->Bcc)){
$A[1] = $this->Bcc;
}
if(!empty($this->Cc)){
$A[2] = $this->Cc;
}
foreach($A as $cle => $tmp_to){
if(substr_count($tmp_to, ',')){
$tmp_to = explode(',', $tmp_to);
foreach($tmp_to as $cle => $tmp_A){
if(!$this->Commande('RCPT TO:<'.$tmp_A.'>', array(250,251), 'Envoie du mail impossible car le serveur n' accèpte pas la commande RCPT TO !!!')){
return false;
}
}
}else{
if(!$this->Commande('RCPT TO:<'.$tmp_to.'>', array(250,251), 'Envoie du mail impossible car le serveur n' accèpte pas la commande RCPT TO !!!')){
return false;
}
}
}
//**********************************************************************
// On créer les entêtes ( headers ) si c' est pas fait
if(empty($header)){
if(!$header = $this->headers()){
$this->erreur .= 'Impossible d' envoyer le mail !!!<br />'."\r\n";
return false;
}
}
//**********************************************************************
// On indique que l' on va envoyer des données
if(!$this->Commande('DATA', 354, 'Envoie du mail impossible car le serveur n' accèpte pas la commande DATA!!!')){
return false;
}
//**********************************************************************
// Envoie de l' entête et du message
fputs($this->smtp_connection, $header);
fputs($this->smtp_connection, "\r\n.\r\n");
$reponce = $this->get_smtp_data();
// Debug
if($this->debug){
echo '<div style="color:#993300;">Entête et message :<br />',"\r\n",'<div style="padding-left:25px;">',str_replace(array("\r\n","\n"), '<br />', $header),'<br />',"\r\n",$message,'</div>',"\r\n",'</div>',"\r\n",str_replace("\r\n", '<br />', $reponce['msg']);
}
if($reponce['code'] !== 250 && $reponce['code'] !== 354){
$this->erreur = 'Envoie du mail impossible !!!<br />'."\r\n"
.'Numéro de l' erreur: '.$reponce['code'].'<br />'."\r\n"
.'Message renvoyé: '.$reponce['msg'].'<br />'."\r\n";
return false;
}
//**********************************************************************
// Variables temporairement modifiées
if($to === $this->To){
$this->To = '';
}
if($subject === $this->Sujet){
$this->Sujet = '';
}
//**********************************************************************
// Déconnection automatique
//**********************************************************************
if($auto_disconnect){// Auto déconnection ?
$this->Deconnection_SMTP();// Déconnection
}
//**********************************************************************
// Mail envoyé
//**********************************************************************
return true;
}
//**************************************************************************
// Lecture des données renvoyées par le serveur SMTP
//**************************************************************************
function get_smtp_data(){
$data = '';
while($donnees = fgets($this->smtp_connection, 515)){// On parcour les données renvoyées
$data .= $donnees;
if(substr($donnees,3,1) == ' ' && !empty($data)){break;}// On vérifi si on a toutes les données
}
// Renvoie des données : array(Code, message complet)
return array('code'=>(int)substr($data, 0, 3), 'msg'=>$data);
}
//**************************************************************************
// Execution des commandes SMTP
//**************************************************************************
function Commande($commande, $bad_error, $msg_error='', $debug=1){
if(!empty($this->smtp_connection)){
fputs($this->smtp_connection, $commande."\n");
$reponce = $this->get_smtp_data();
// Debug
if($this->debug && $debug){
echo '<div style="color:#993300;">',htmlentities($commande),'</div>',"\r\n",str_replace("\r\n", '<br />', $reponce['msg']);
}
// Tableau de code valide
if((is_array($bad_error) && !in_array($reponce['code'], $bad_error)) || (!is_array($bad_error) && $reponce['code'] !== $bad_error)){
if($msg_error){
$this->erreur = $msg_error.'<br />'."\r\n"
.'Numéro de l' erreur: '.$reponce['code'].'<br />'."\r\n"
.'Message renvoyé: '.$reponce['msg'].'<br />'."\r\n";
}
if(!$debug){
return array('no_error'=>false, 'msg'=>$reponce['msg']);
}else{
return false;
}
}
if(!$debug){
return array('no_error'=>true, 'msg'=>$reponce['msg']);
}else{
return true;
}
}else{
$this->erreur = 'Impossible d' éxecuter la commande <span style="font-weight:bolder;">'.$commande.'</span> car il n' y a pas de connection !!!<br />'."\r\n";
if(!$debug){
return array('no_error'=>false, 'msg'=>'');
}else{
return false;
}
}
}
//**************************************************************************
// Fonction de déconnection SMTP
//**************************************************************************
function Deconnection_SMTP(){
if(!empty($this->smtp_connection)){
if(!$this->Commande('QUIT', 221, 'Impossible de se déconnecter !!!')){
return false;
}
@sleep(5);// On laisse 5 seconde au serveur pour terminer toutes les instructions
if(!fclose($this->smtp_connection)){
$this->erreur = 'Impossible de se déconnecter !!!<br />'."\r\n";
return false;
}
$this->smtp_connection = 0;
return true;
}
$this->erreur = 'Impossible de se déconnecter car il n' y a pas de connection !!!<br />'."\r\n";
return false;
}
}
?>
Conclusion
Pour envoyer un mail : <?php include('./Class.SMTP.php');
// Remplissez le champs login et pass si vous avez besoin de vous identifier // SMTP('smtp.serveur.fr', 'login', 'pass');
// SMTP sans authentification // SMTP('smtp.serveur.fr');
$smtp = new SMTP('smtp.serveur.fr', 'login', 'pass');
$smtp->smtp_mail('to@you.com', 'sujet', 'message');// Envoie du mail
if(!$smtp->erreur){ echo '<div style="text-align:center; color:#008000;">Votre mail a bien été envoyé.</div>',"\r\n"; }else{// Affichage des erreurs echo $smtp->erreur; } ?>
Historique
- 04 mai 2006 23:02:16 :
- Petit bug :-/
- 26 novembre 2006 21:43:15 :
- Ajout de la fonction "pièce jointe" ;-)
- 27 novembre 2006 10:23:00 :
- oublis ^^
- 02 décembre 2006 17:38:37 :
- Correction d' un petit bug et ajout d' un exmple complet
- 04 décembre 2006 16:10:46 :
- Petites erreurs corrigées ^^
- 23 février 2007 01:50:31 :
- Suppression de quelque bug.
Maintenant on peut envoyer des copies cachée (Bcc) et des copies simple (Cc)
Meilleur gestion des erreurs
- 10 mars 2008 11:03:10 :
- - Ajout de la fonction d' encodage
- Traduction en anglais
- Introduction du support tls (ssl)
- 04 octobre 2008 12:23:53 :
- - Correction d' un bug qui fermait partiellement la connection, empêchant un autre envoie direct via la même connection.
- Ajout d' un exemple pour envoyer à de multiple adresses -emails
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Mail et formulaire [ par Jackboy ]
J'aimerai créer un formulaire, assez complexe (pas seulement email, nom, message,...) et j'aimerai avoir ce formulaire envoyer dans un email et format
formulaire pour e-mail invisible [ par pyranhaz ]
Bonjour,Je cherche à élaborer un formulaire php afin que les clients de mes petites annonces puissent envoyer leur réponse sans connaître le e-mail du
Envoi d'un email via smtp [ par Bruto ]
J'aurais besoin d'envoyer des emails via mon serveur smtp ayant l'adresse 172.16.10.111 et donc totalement indépendant de mon serveur apache.J'utilise
Problème de compatibilité de script [ par Chris54 ]
Bonjour,J'ai un problème d'execution d'un script javascript sous netscape alors qu'il fonctionne parfaitement sous IE mais je ne sais pas pourquoi.Que
aidez moi pb avec email !! [ par anisbs ]
Salut je suis débutant en phpje commence a essayer quelques trucs mais la fonction mail ne fonctionne pas Il me sort un truc comme :Warning: mail():
envoie d'Email :Je dois avoir de la merde dans les yeux [ par Wam0106 ]
Voila chez Online.net il me dise qu'il y a une erreure a la ligne 3 mais je ne vois pas ou est le pb si qq'un peu me dire ce qui ne va pas:<? $head
Pb avec Mail() [ par faluma972 ]
Slt,j'ai un pb avk la fonction Mail()!je veux pouvoir envoyer un mail à kelk1 en ayant son email en paramètre $email mais ca ne fonctionne pas!Que doi
fonction mail ? [ par badjouane ]
comment puis evité le "/" qui jalone les mail que j'envoi à partir de la section administration de mon site.Par exemple, si j'écri :Mes c'est quoi ce
Capter l'email une fois lu. [ par zzzzzz ]
Salutj'aimerai savoir si il y a un moyen de "capter" l'email d'un destinataire. Si par exemple j'envoie un mail à bidon@hotmail.comj'aimerai appellé u
Envoyer bcp de email avec mail() [ par ImmortalPC ]
Salut, Je me pose à un gros problème sur un de mes scripts, envoyer beaucoup d'email ( environs 20 000 ). Le problème c'est le time ou
|
Derniers Blogs
UNE JOLIE-HORLOGE ET PAS QU'UN PEU !UNE JOLIE-HORLOGE ET PAS QU'UN PEU ! par neodante
Pour les possesseurs d'iPhone, ça y est Bijin Tokei - qui se traduit littéralement en Français par " Jolie Horloge " - est arrivé et GRATUITEMENT s'il vous plaît ! Après la version Tokyo, Hokkaido, night club, racing, Gal, "pour les mademoiselles'", . voi...
Cliquez pour lire la suite de l'article par neodante TECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICESTECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICES par ROMELARD Fabrice
Animé par: Gaetan Bouveret et Julien Chomarat Business Connectivity Services (BCS) est dans SharePoint 2010 la version 2 de Business Data Catalog (BDC dans SharePoint 2007). Il s'agit de la solution permettant de visualiser des données provenan...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE[DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE par orion
Comme de nombreux geek, je suis un grand amateur de série TV et je rate régulièrement des épisodes de mes séries préférés. Une solution s'offre à vous avec ce merveilleux site : Tv Gorge - www.tvgorge.com Moteur de recherche à l'appui, vous pouvez ...
Cliquez pour lire la suite de l'article par orion TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|