Language PHP : Hypertext Preprocessor

 Charge moyenne sur 1mn : 0.00 Charge moyenne sur 5mn : 0.02 Charge moyenne sur 15mn : 0.00


PHP

PHP is a popular general-purpose scripting language that is particularly suited for web development.

Fast, flexible and pragmatic, PHP is made for any blog or for all the most popular sites in the world.

The word PHP or programming language contained in web pages and executed on servers, they return the result directly to the client who can never see the source. Allows you to create dynamic web pages.

PHP.Net © 2001-2020 The PHP Group: Language Reference

Predefined PHP classes to make our life easier :)






Site user blocks : Account info / user rights / summary

Envoyer un mail depuis PHP

Envoyer un mail en mode type : multipart/alternative

Informations :

Dates
  • Publish : : 2010
  • Modification : Thursday 01 september 2011

  • 3715 views

Share :

Script avec 160 lignes

001[php]
002if($_POST) {
003
004$title = explode(' < ', $this→page['out']['title']);
005$title = array_reverse($title);
006
007
008    if( !empty($_POST['nom']) && !empty($_POST['email']) && !empty($_POST['message']) ) {
009
010 
011	# Config
012
013	$formulaire['select'][1]['titre']    = $title[2].' > '.$title[1];
014	$formulaire['select'][1]['email'][0] = 'email_1@domaine.tld';
015	$formulaire['select'][1]['email'][1] = 'email_2@domaine.tld';
016
017
018      
019        $date = mktime(0, 0, 0, substr(date("Y-m-d"),5,2), substr(date("Y-m-d"),8,2), substr(date("Y-m-d"),0,4));
020        $date = date("d",$date)."/".date("m",$date)."/".date("Y");
021        $heure = date("Hhi");
022               
023        $post_civilite = $_POST['civilite'];
024        $post_nom = $_POST['nom'];
025        $post_prenom = $_POST['prenom'];
026        $post_email = $_POST['email'];
027       
028        $post_message = $_POST['message'];
029
030        if($post_email != '') {
031            //$type_contact = $formulaire['select'][1]['titre'];
032            foreach($formulaire['select'][1]['email'] as $email) {
033              $destinaires.= $email.',';
034            }
035        }
036
037        $subject   = 'Titre mail : ';
038        $subject  .= $formulaire['select'][1]['titre'];
039
040        //-----------------------------------------------
041        //MESSAGE TEXTE
042        //-----------------------------------------------
043       
044        $message_text = ''.$subject.''."n";
045   
046        $message_text.= '' . "n";
047        $message_text.= $post_message."n";
048        $message_text.= '' . "n";
049
050        $message_text.= '' . "n";
051       
052        $message_text.= 'Identification de l'internaute' . "n";
053       
054        $message_text.= ''."n";
055        $message_text.= '* Prénom Nom : '.$post_civilite.' '.$post_prenom.' '.$post_nom.'' . "n";
056        $message_text.= '* Email : '.$post_email.''."n";
057         
058        if(isset($_SERVER["HTTP_X_USER_AGENT"]) )
059          $message_text.= '* Navigateur : '.$_SERVER["HTTP_X_USER_AGENT"].'' . "n";
060        else
061          $message_text.= '* Navigateur : '.$_SERVER["HTTP_USER_AGENT"].'' . "n";
062
063        if(isset($_SERVER["HTTP_X_USER_AGENT"]) )
064          $message_text.= '* IP : '.$_SERVER["HTTP_X_FORWARDED_IP"].'' . "n";
065        else
066          $message_text.= '* IP : '.$_SERVER["REMOTE_ADDR"].'' . "n";
067
068        if(isset($_SERVER["HTTP_VIA"]) )
069          $message_text.= '* IP VIA : '.$_SERVER["HTTP_VIA"].'' . "n";
070                   
071        $message_text.= '* Date : '.$date.' - '.$heure.'' . "n";
072        $message_text.= '' . "n";
073
074        //-----------------------------------------------
075        //MESSAGE HTML
076        //-----------------------------------------------
077           
078        $message_html = '<h2>'.$subject.'</h2>'."n";
079   
080        $message_html.= '<p>'."n";
081        $message_html.= $post_message."n";
082        $message_html.= '</p>'."n";
083
084        $message_html.= '<hr />'."n";
085       
086        $message_html.= '<h3>Identification de l'internaute/h3>'."n";
087       
088        $message_html.= '<ul>'."n";
089        $message_html.= '  <li>Prénom Nom : '.$post_civilite.' '.$post_prenom.' '.$post_nom.''."n";
090        $message_html.= '  <li>Email : <a href="mailto:'.$post_email.'">'.$post_email.'</a>'."n";
091         
092        if(isset($_SERVER["HTTP_X_USER_AGENT"]) )
093          $message_html.= '  <li>Navigateur : '.$_SERVER["HTTP_X_USER_AGENT"].''."n";
094        else
095          $message_html.= '  <li>Navigateur : '.$_SERVER["HTTP_USER_AGENT"].''."n";
096
097        if(isset($_SERVER["HTTP_X_USER_AGENT"]) )
098          $message_html.= '  <li>IP : '.$_SERVER["HTTP_X_FORWARDED_IP"].''."n";
099        else
100          $message_html.= '  <li>IP : '.$_SERVER["REMOTE_ADDR"].''."n";
101
102        if(isset($_SERVER["HTTP_VIA"]) )
103          $message_html.= '  <li>IP VIA : '.$_SERVER["HTTP_VIA"].''."n";
104                   
105        $message_html.= '  <li>Date : '.$date.' - '.$heure.''."n";
106        $message_html.= '</ul>'."n";
107
108
109        //-----------------------------------------------
110        //GENERE LA FRONTIERE DU MAIL ENTRE TEXTE ET HTML
111        //-----------------------------------------------
112       
113        $frontiere = '-----=' . md5(uniqid(mt_rand()));
114       
115        //-----------------------------------------------
116        //HEADERS DU MAIL
117        //-----------------------------------------------
118    
119        $headers  = 'From: "'.$post_nom.' '.$post_prenom.'" <'.$post_email.'>' . "rn";
120        //$headers = 'From: '.$post_email.'' . "rn" .
121        $headers .= 'Return-Path: <'.$post_email.'>' . "rn";
122        $headers .= 'X-Mailer: PHP/' . phpversion() . "rn";
123        $headers .= 'MIME-Version: 1.0' . "rn";
124        $headers .= 'Content-Type: multipart/alternative; boundary="'.$frontiere.'"' . "rn";
125        $headers .= 'Content-Type: text/html; charset="iso-8859-1"' . "rn";
126       
127
128        //-----------------------------------------------
129        //MESSAGE TEXTE
130        //-----------------------------------------------
131       
132        $message  = 'This is a multi-part message in MIME format.' . "nn";
133        $message .= '--'.$frontiere.'' . "n";
134        $message .= 'Content-Type: text/plain; charset="iso-8859-1"' . "n";
135        $message .= 'Content-Transfer-Encoding: 7bit' . "nn";
136        $message .= addslashes(stripslashes($message_text))."nn";
137       
138         //-----------------------------------------------
139         //MESSAGE HTML
140         //-----------------------------------------------
141        
142         $message .= '--'.$frontiere.'' . "n";
143         $message .= 'Content-Type: text/html; charset="iso-8859-1"'."n";
144         $message .= 'Content-Transfer-Encoding: quoted-printable'."nn";
145         $message .= addslashes(stripslashes($message_html))."nn";
146   
147         $message .= '--'.$frontiere.'--' . "n";
148       
149         //-----------------------------------------------
150
151
152        if( mail($destinaires, $subject, $message, $headers) ) {
153          echo 'Votre message a bien été envoyé...';
154        } else {
155            echo 'Votre message n'a pas été envoyé !';
156        }
157       
158          
159    }
160} [/php]





Author of the page

O.Romain.Jaillet-ramey

O.Romain.Jaillet-ramey

  • Firstname : Olivier Romain Luc
  • Lastname : : Jaillet-ramey
  • Arrived on tuesday 19 october 1976 (1976/10/19 00:00)
    47 years activity !

Translate this page with Google

Firefox Nighlty

Our friends from Framasoft are interested in Mozilla and asked them questions about Nightly: Firefox Night-club, free entry !






Load page: 3.0295381546021