La Communauté Webmaster  forum rss


  Forum-webmaster
  Technique - programmation
  PHP / MySQL
(Modérateurs: Shain, Jey, erwinol, Lilian, lauryv, ToToMaStEr)
  Problème de formulaire avec pièce jointe
« Précédent Suivant »
Pages: [1] Descendre
Répondre    Aviser des réponses    Envoyer le sujet    Imprimer
  Auteur  Sujet: Problème de formulaire avec pièce jointe  (Lu 909 fois)
Problème de formulaire avec pièce jointe
« sur: le 22-04-2005 a 16:36:15 »
Fbrip
Membre récent
*

Hors-Ligne

Messages: 1



Je suis un lama!

Voir le Profil
Répondre avec citation

Bonjour,
Un ami m'a aidé à réaliser un formulaire en PHP pour permettre de recevoir des données ainsi qu'une pièce jointe.

Cependant celui-ci ne fonctionne pas :
Lorsque je remplis les champs et envoi le formulaire, j'obtiens le message suivant :
Warning: copy(/cvtemp/xlt.doc): failed to open stream: No such file or directory in /home/.sites/78/site85/web/cvmail.php on line 232/cvtemp/xlt.doc ne peut etre trouve

Je ne sais comment faire pour faire fonctionner ce formulaire.. Le site est hébergé chez AMEN.
Voici le code utilisé dans mon fichier cvmail.php :


<?
$dest="admin@doryan.fr";
$reponse=StripSlashes("Candidature");
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 "Erreur au niveau de l expediteur !";
                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;
}


/*                Send()
*                fornat and send the mail
*/

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++ ) {
                $res = mail($this->sendto[$i], $this->msubject,$body, $this->headers);

        }

}



function Organization( $org )
{
        if( trim( $org != "" )  )
                $this->organization= $org;
}




function Priority( $priority )
{

        if( ! intval( $priority ) )
                return false;

        if( ! isset( $this->priorities[$priority-1]) )
                return false;

        $this->priority= $this->priorities[$priority-1];

        return true;

}



function Attach( $filename, $filetype='application/x-unknown-content-type', $disposition = "inline" )
{

        $this->aattach[] = $filename;
        $this->actype[] = $filetype;
        $this->adispo[] = $disposition;
}


/*                Get()
*                return the whole e-mail , headers + message
*                can be used for displaying the message in plain text or logging it
*/

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|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 "Erreur dans l adresse mail";
                        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") );

        $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];        // content-type
                $disposition = $this->adispo[$i];

                if( ! file_exists( $filename) ) {
                        echo "$filename ne peut etre trouve"; 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 );

/*
               
                $deb=0; $len=76; $data_len= strlen($data);
                do {
                        $ata[$k++]= substr($data,$deb,$len);
                        $deb += $len;
                } while($deb < $data_len );

*/
        }
        $this->attachment= implode($sep, $ata);
}


}

$subject=StripSlashes($subject);
$msg=StripSlashes($msg);
$msg="Message depuis votre site web:
$msg";
$m= new Mail;
        $m->From( "$email" );
        $m->To( "$dest");   
        $m->Subject( "$subject" );
        $m->Body( $msg);     
if ($email1!="") {
        $m->Cc( "$email1");
   }
        $m->Priority($priority) ; 
if ("$NomFichier_name"!="") {
   copy("$NomFichier","/cvtemp/$NomFichier_name");
   $m->Attach( "/cvtemp/$NomFichier_name", "application/octet-stream" );
   }
        $m->Send();
if ("$NomFichier_name"!="") {
Unlink("/cvtemp/$NomFichier_name");  }   
echo "$reponse";

?>

Si quelqu'un a une idée..
Voici également le fichier form.html que j'utilise :

<form vname="FormName" action="../cvmail.php" method="post" enctype="multipart/form-data" name="form">
<table border="0" cellpadding="5" cellspacing="0" width="137">
   <tr>
      <td>Nom :</td>
      <td><input type="text" name="subject" size="60"></td>
   </tr>
   <tr>
      <td>Adresse mail :</td>
      <td><input type="text" name="email" size="60"></td>
   </tr>
   <tr>
      <td>Motivations</td>
      <td><textarea rows="12" name="msg" cols="60"></textarea></td>
   </tr>
   <tr>
      <td>Votre CV :</td>
      <td><input type="hidden" name="MAX_FILE_SIZE" value="100000"><input name="NomFichier" type="file" size="16"></td>
   </tr>
   <tr>
      <td>&nbsp;</td>
      <td>
         <div align="left">
             <input type="submit" value="Envoyer"></div>
      </td>
   </tr>
</table>
</form>

Rapporter au modérateur  
Répondre    Aviser des réponses    Envoyer le sujet    Imprimer
Pages: [1] Monter
« Précédent Suivant »
Sauter à: 

Votre statut : Invité
Vous devez être membre pour participer.
 
 
Let’s Encrypt : le certificat SSL gratuit
Tester votre site internet sur différents navigateurs
[WordPress] Des problèmes avec l’administration ?
Rappel : Mettez à jour vos CMS et vos sites E-commerce
Le .fr fête ses 25 années d’existence !
Mesurer votre audience en temps réel avec BubbleStat
Porter réclamation contre Google Panda ?
Zlio n’est plus …
 
 
 
 
 

Copyright (c) Devclic 2002 - 2026 - Tous droits réservés

creation site internet strasbourg