<?php
/*----------------------- Installation -------------------------
Utilité >> Envoi un fichier fichier joint
Nom du fichier >> envoi.php
Créé le >> 17/09/01
1°) Donner l'action du formulaire vers ce fichier
2°) Créer un repertoire (dossier) nommé "transit"
à la racine de votre site,
et mettez le en CHMOD 777
(voir $NomFichier_name)
>> pour toutes informations >>
http://www.akoter.com/forum/
--------------------------------------------------------------*/
$destinataire = $email_destinaire ; // destinatiare du message
$copie_conforme = ""; // copie conforme
$cache_destinataire = ""; // email de surveillance
$objet_page = $subject ; // sujet du message
$redirection = "http://www.monsite.com/mapage.html"; // page de redrection dés le message envoyé
$priorite = $priorite ; // définition de la priorité du message
$reponse=StripSlashes("Votre message est envoyé ;o)"); // confirmation de l'envoi
// ----------------- début du Code ---------------------- //
class Mail {
var $sendto= array();
var $from, $msubject;
var $acc= array();
var $abcc= array();
var $aattach= array();
var $priorities= array( '1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)' );
function Mail() {
$this->autoCheck(true);
}
function autoCheck($bool) {
if($bool)
$this->checkAddress = true;
else
$this->checkAddress = false;
}
function Subject($subject) {
$this->msubject = strtr($subject, "\r\n" , " " );
}
function From($from) {
if( ! is_string($from) ) {
echo "Class Mail: Erreur, From n'est pas de la bonne forme";
exit;
}
$this->from= $from;
}
function To( $to ) {
if( is_array( $to ) )
$this->sendto= $to;
else
$this->sendto[] = $to;
if( $this->checkAddress == true )
$this->CheckAdresses( $this->sendto );
}
function Cc($cc) {
if( is_array($cc) )
$this->acc= $cc;
else
$this->acc[]= $cc;
if( $this->checkAddress == true )
$this->CheckAdresses( $this->acc );
}
function Bcc($bcc) {
if( is_array($bcc) ) {
$this->abcc = $bcc;
} else {
$this->abcc[]= $bcc;
}
if( $this->checkAddress == true )
$this->CheckAdresses( $this->abcc );
}
function Body($body) {
$this->body= $body;
}
function Send() {
$this->_build_headers();
if( sizeof( $this->aattach > 0 ) ) {
$this->_build_attachement();
$body = $this->fullBody . $this->attachment;
}
for( $i=0; $i< sizeof($this->sendto); $i++ ) { // envoie du mail aux destinataires principaux
$res = mail($this->sendto[$i], $this->msubject,$body, $this->headers);
}
}
function Organization($org) {
if( trim( $org != "" ) )
$this->organization= $org;
}
function Priority($priorite) {
if( ! intval($priorite) )
return false;
if( ! isset($this->priorities[$priorite-1]) )
return false;
$this->priority= $this->priorities[$priorite-1];
return true;
}
function Attach( $filename, $filetype='application/x-unknown-content-type', $disposition = "inline" ) {
$this->aattach[] = $filename;
$this->actype[] = $filetype;
$this->adispo[] = $disposition;
}
function Get() {
$this->_build_headers();
if( sizeof( $this->aattach > 0 ) ) {
$this->_build_attachement();
$this->body= $this->body . $this->attachment;
}
$mail = $this->headers;
$mail .= "\n$this->body";
return $mail;
}
function ValidEmail($address) {
if( ereg( ".*<(.+)>", $address, $regs ) ) {
$address = $regs[1];
}
if(ereg( "^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|fr|com|gov|mil|org|edu|int)\$",$address) )
return true;
else
return false;
}
function CheckAdresses($aad) {
for($i=0;$i< sizeof( $aad); $i++ ) {
if( ! $this->ValidEmail( $aad[$i]) ) {
echo "Class Mail, method Mail : Adresse Invalide $aad[$i]";
exit;
}
}
}
function _build_headers() {// creation du header mail
$this->headers= "From: $this->from\n";
$this->to= implode( ", ", $this->sendto );
if( count($this->acc) > 0 ) {
$this->cc= implode( ", ", $this->acc );
$this->headers .= "CC: $this->cc\n";
}
if( count($this->abcc) > 0 ) {
$this->bcc= implode( ", ", $this->abcc );
$this->headers .= "BCC: $this->bcc\n";
}
if( $this->organization != "" )
$this->headers .= "Organization: $this->organization\n";
if( $this->priority != "" )
$this->headers .= "X-Priority: $this->priority\n";
}
function _build_attachement() {
$this->boundary= "------------" . md5( uniqid("myboundary") ); // TODO : variable bound
$this->headers .= "MIME-Version: 1.0\nContent-Type: multipart/mixed;\n boundary=\"$this->boundary\"\n\n";
$this->fullBody = "This is a multi-part message in MIME format.\n--$this->boundary\nContent-Type: text/plain; charset=us-ascii\nContent-Transfer-Encoding: 7bit\n\n".$this->body."\n";
$sep= chr(13) . chr(10);
$ata= array();
$k=0;
for( $i=0; $i < sizeof($this->aattach); $i++) {
$filename = $this->aattach[$i];
$basename = basename($filename);
$ctype = $this->actype[$i];
$disposition = $this->adispo[$i];
if( ! file_exists( $filename) ) {
echo "Class Mail, method attach : file $filename can't be found"; exit;
}
$subhdr= "--$this->boundary\nContent-type: $ctype;\n name=\"$basename\"\nContent-Transfer-Encoding: base64\nContent-Disposition: $disposition;\n filename=\"$basename\"\n";
$ata[$k++] = $subhdr;
// non encoded line length
$linesz= filesize($filename)+1;
$fp= fopen( $filename, 'r' );
$data= base64_encode(fread( $fp, $linesz));
fclose($fp);
$ata[$k++] = chunk_split( $data );
}
$this->attachment= implode($sep, $ata);
}
}
function redir($redirection) { // redirection JavaScript
echo "<script language=\"javascript\">";
echo "window.location=('".$redirection."');";
echo "</script>";
}
$subject=StripSlashes($subject);
$msg=StripSlashes($msg); // construction du message email
$msg ="Message depuis votre site web :\n\n" ;
$msg .= "Subjet : ".$objet_page."\n" ;
$msg .= "Message : ".$message ;
$m= new Mail; // création du email
$m->From($email); // création du destinataire
$m->To($destinataire); // création de l'expéditeur
$m->Subject($subject); // création du sujet
$m->Body($msg); // création du message
if ($copie_conforme!='') { //S'il y a une copie conforme du mail
$m->Cc($copie_conforme);
}
$m->Priority($priorite) ;
if ($cache_destinataire!='') { //S'il y a une copie cachée du mail
$m->Bcc($cache_destinataire);
}
$m->Priority($priorite) ;
if ($NomFichier_name !='') { // attache le fichier joint
copy($NomFichier,"./transit/".$NomFichier_name."");
$m->Attach( "./transit/".$NomFichier_name."", "application/octet-stream" );
}
$m->Send(); /* Envoi du mail */
if ($NomFichier_name!='') {
Unlink("./transit/".$NomFichier_name."");
}
echo $reponse ;// Affichage du message d'envoi réussi
if ($redirection !='') {
redir($redirection); // renvoie sur une page spécifique
}
?>