IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Envoi de mail en texte, html, avec pièces-jointes et images....


Sujet :

Langage PHP

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    72
    Détails du profil
    Informations personnelles :
    Âge : 33
    Localisation : Suisse

    Informations forums :
    Inscription : Mars 2007
    Messages : 72
    Points : 36
    Points
    36
    Par défaut Envoi de mail en texte, html, avec pièces-jointes et images....
    Bonjour,

    Je cherche déjà désespérément depuis des mois un bon script pour envoyer des mails en format texte et html ainsi qu'avec une pièce-jointe et une/des photo(s).

    J'ai trouvé un script qui m'a l'aire assez complet. Le seul problème de celui-ci est que le message en version html se met en pièce-jointe. C'est peut-être un truc tout con....

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    # File for Attachment 
    $file="Facture241.pdf";
    $f_name="Factures/".$file;    // use relative path OR ELSE big headaches. $letter is my file for attaching. 
    $handle=fopen($f_name, 'rb'); 
    $f_contents=fread($handle, filesize($f_name)); 
    $f_contents=chunk_split(base64_encode($f_contents));    //Encode The Data For Transition using base64_encode(); 
    $f_type=filetype($f_name); 
    fclose($handle); 
    # To Email Address 
    $emailaddress="xxx@xxx.com"; 
     
    # Message Subject 
    $emailsubject="Heres An Email with a PDF".date("Y/m/d H:i:s"); 
     
    # Message Body 
    ob_start(); 
      require("emailbody.php");     // i made a simple & pretty page for showing in the email 
    $body=ob_get_contents(); ob_end_clean(); 
     
    # Common Headers 
    $headers .= 'From: Jonny <xxx@xxx.com>'.$eol; 
    $headers .= 'Reply-To: Jonny <xxx@xxx.com>'.$eol; 
    $headers .= 'Return-Path: Jonny <xxx@xxx.com>'.$eol;     // these two to set reply address 
    $headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol; 
    $headers .= "X-Mailer: PHP v".phpversion().$eol;           // These two to help avoid spam-filters 
    # Boundry for marking the split & Multitype Headers 
    $mime_boundary=md5(time()); 
    $headers .= 'MIME-Version: 1.0'.$eol; 
    $headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol; 
    $msg = ""; 
     
    # Attachment 
    $msg .= "--".$mime_boundary.$eol; 
    $msg .= "Content-Type: application/pdf; name=\"".$file."\"".$eol;   // sometimes i have to send MS Word, use 'msword' instead of 'pdf' 
    $msg .= "Content-Transfer-Encoding: base64".$eol; 
    $msg .= "Content-Disposition: attachment; filename=\"".$file."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !! 
    $msg .= $f_contents.$eol.$eol; 
    # Setup for text OR html 
    $msg .= "Content-Type: multipart/alternative".$eol; 
     
    # Text Version 
    $msg .= "--".$mime_boundary.$eol; 
    $msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol; 
    $msg .= "Content-Transfer-Encoding: 8bit".$eol; 
    $msg .= "This is a multi-part message in MIME format.".$eol; 
    $msg .= "If you are reading this, please update your email-reading-software.".$eol; 
    $msg .= "+ + Text Only Email from Genius Jon + +".$eol.$eol; 
     
    # HTML Version 
    $msg .= "--".$mime_boundary.$eol; 
    $msg .= "Content-Type: text/html; charset=iso-8859-1".$eol; 
    $msg .= "Content-Transfer-Encoding: 8bit".$eol; 
    $msg .= $body.$eol.$eol; 
     
    # Finished 
    $msg .= "--".$mime_boundary."--".$eol.$eol;   // finish with two eol's for better security. see Injection. 
     
    # SEND THE EMAIL 
    ini_set(sendmail_from,'xxx@xxx.com');  // the INI lines are to force the From Address to be used ! 
      mail($emailaddress, $emailsubject, $msg, $headers); 
    ini_restore(sendmail_from);
    Et le fichier "emailbody.php" :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    Salut,<br><br>
     
    <a href="http://www.google.com">P'tit test</a> PEtit etest !!! :DFsdsdfg<br><br>
     
    Ouais, ouais !!! :D
    Merci beaucoup d'avance !

  2. #2
    Modérateur
    Avatar de Vil'Coyote
    Homme Profil pro
    Développeur adélia & Web
    Inscrit en
    Février 2008
    Messages
    4 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur adélia & Web
    Secteur : Industrie

    Informations forums :
    Inscription : Février 2008
    Messages : 4 583
    Points : 7 503
    Points
    7 503
    Par défaut
    ba le truc tout con c'est que tu peux pas mettre deux type contente dans u même corps de message.
    soit tu définie ton mail en format html soit en format text mais tu ne met pas les deux dans ton code comme tu l'indique là.

Discussions similaires

  1. [AC-2003] Envoi mail à liste de destinataires avec pièce jointe et sans Outlook
    Par philippe.desrues dans le forum VBA Access
    Réponses: 1
    Dernier message: 11/07/2013, 15h35
  2. [Mail] problème mail html avec pièce jointe
    Par stars333 dans le forum Langage
    Réponses: 2
    Dernier message: 12/06/2007, 19h44
  3. Réponses: 1
    Dernier message: 09/05/2007, 21h36

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo