mail avec fichier joint

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : mail avec fichier joint

par Chile » 06 juil. 2006, 05:31

merci Henri,
j'ai trouvé la réponse http://phpcodeur.net/wascripts/wamailer/[/url]

par Henri » 30 juin 2006, 13:47

les envois de mail avec pièces jointes ou HTML, c'est la vraie galère. Pas à cause de PHP, mais parce qu'au départ, les mails c'était fait pour envoyer du texte brut et qu'on a rajouté des rustines pour d'autres usages.

Donc un conseil : utilise cette excellente bibliothèque qui fait ça très bien : http://www.phpguru.org/static/mime.mail.html

mail avec fichier joint

par Chile » 30 juin 2006, 03:05

Bonjour,
J'ai effectué des recherches sur le forum pour mon probleme, mais j'ai pas trouvé de solution :?
J'ai un formulaire dans lequel se trouve un champ joindre un fichier. Je veux donc envoyer ce formulaire en mail avec le fichier joint. Les données arrivent bien mais pas le fichier...et en bas du mail se trouve une succession de code :?
voici mon script si qlq peut m'aider ou m'orienter...merci
<?php 
if(!isset($_FILES)) { $_FILES = $HTTP_POST_FILES; } 
// Les variables
$nom=$_POST['nom']; 
$prenom=$_POST['prenom']; 
$adresse=$_POST['adresse']; 
$ville=$_POST['ville']; 
$cp=$_POST['cp']; 
$telephone1=$_POST['telephone1']; 
$telephone2=$_POST['telephone2']; 
$email=$_POST['email']; 
$gardenf=$_POST['gardenf']; 
$menage=$_POST['menage']; 
$repassage=$_POST['repassage']; 
$comment=$_POST['comment'];
$heures=$_POST['heures']; 
$crenaux=$_POST['crenaux']; 

$msg="<html>";
$msg .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong><em>Recrutement</em></strong><br />";
$msg .= "<br />";
$msg .= "<strong><em>Nom:</em></strong>:<br />";
$msg .= "\t$nom\n<br />";
$msg .= "<strong><em>Prénom:</em></strong>:<br />";
$msg .= "\t$prenom\n<br />";
$msg .= "<strong><em>Adresse:</em></strong>:<br />";
$msg .= "\t$adresse\n<br />";
$msg .= "<em><strong>Code postale:</strong></em><br />";
$msg .= "\t$cp\n<br />";
$msg .= "<em><strong>Téléphone 1:</strong></em><br />";
$msg .= "\t$telephone1\n<br />";
$msg .= "<em><strong>Téléphone 2:</strong></em><br />";
$msg .= "\t$telephone2\n<br />";
$msg .= "<em><strong>E-mail:</strong></em><br />";
$msg .= "\t$email\n<br />";
$msg .= "<em><strong>Interessé par:</strong></em><br />";
$msg .= "\t$gardenf&nbsp;$menage&nbsp;$repassage\n<br />";
$msg .= "<em><strong>Commentaires:</strong></em><br />";
$msg .= "\t$comment\n<br />";
$msg .= "<em><strong>Nombre d'heures:</strong></em><br />";
$msg .= "\t$heures\n<br />";
$msg .= "<em><strong>Crénaux:</strong></em><br />";
$msg .= "\t$crenaux\n<br />";
$msg .="<html>";

$email2="[email protected]";
$sujet="Recrutement";

$Headers  = "Content-Type:text/html;charset=iso-8859-1\n";
$Headers .= "Content-Transfer-Encoding: 8bit\n";

// Obtain file upload vars 

$fileatt      = $_FILES['cv']['tmp_name']; 
$fileatt_type = $_FILES['cv']['type']; 
$fileatt_name = $_FILES['cv']['name']; 

if (is_uploaded_file($fileatt)) { 
// Read the file to be attached ('rb' = read binary) 
$file = fopen($fileatt,'rb'); 
$data = fread($file,filesize($fileatt)); 
fclose($file); 

   // Generate a boundary string 
$semi_rand = md5(time()); 
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
       
  // Base64 encode the file data 
$data = chunk_split(base64_encode($data)); 

// Ajout du fichier au message
$msg .= "--{$mime_boundary}\n" . 
             "Content-Type: {$fileatt_type};\n" . 
             " name=\"{$fileatt_name}\"\n" . 
             "Content-Disposition: attachment;\n" . 
             " filename=\"{$fileatt_name}\"\n" . 
             "Content-Transfer-Encoding: base64\n\n" . 
             $data . "\n\n" . 
             "--{$mime_boundary}--\n"; 
} 

//L'envoi du mail
mail($email2, $sujet, $msg, $Headers);

?>
et coici les codes en bas du mail recu :
--==Multipart_Boundary_x0a3c9625e485cb436a204bb9d82831e6x Content-Type: text/html; name="111-readme.html" Content-Disposition: attachment; filename="111-readme.html" Content-Transfer-Encoding: base64 PGh0bWw+PHRpdGxlPkQtZm9ydW0gOiBSZWFkbWU8L3RpdGxlPg0KPGJvZHkgYmdjb2xvcj0iI0ZG RkZGRiIgdGV4dD0iIzAwMDAwMCIgbGluaz0iIzY2NjZGRiIgdmxpbms9IiNDQ0NDRkYiIGFsaW5r PSIjQ0M5OUZGIj4NCg0KPHRhYmxlIHdpZHRoPSIxMDAlIiBib3JkZXI9IjAiIGNlbGxzcGFjaW5n PSIyIiBjZWxscGFkZGluZz0iMCI+DQogIDx0cj4gDQogICAgPHRkIGhlaWdodD0iNDIiPiANCiAg ICAgIDxkaXYgYWxpZ249ImNlbnRlciI+PGI+PGZvbnQgc2l6ZT0iKzMiPkQgLSBGT1JVTTwvZm9u......