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 :

probleme avec mail en php


Sujet :

Langage PHP

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 12
    Points : 13
    Points
    13
    Par défaut probleme avec mail en php
    Bonjour
    je veux envoyer un mail avec une PJ,je recois mon mail et ma PJ mais jé un probléme dans la mise en page et j'ai un bout de code qui s'affiche dans mon mail
    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
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
     
     
    <?php
    session_start();
    @import_request_variables("EGPCS",""); 
    ?>
    <?php 
    //define the receiver of the email 
    $to = <a href="mailto:moi@gmail.com">moi@gmail.com</a>'; 
    //define the subject of the email 
    $subject = 'mail test'; 
    //create a boundary string. It must be unique 
    //so we use the MD5 algorithm to generate a random hash 
    $random_hash = md5(date('r', time())); 
    //define the headers we want passed. Note that they are separated with \r\n 
    $headers = "From: <a href="mailto:lol@gmail.com">lol@gmail.com</a>\r\nReply-To: <a href="mailto:lol@gmail.com">lol@gmail.com</a>"; 
    //add boundary string and mime type specification 
    $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""; 
    //read the atachment file contents into a string,
    //encode it with MIME base64,
    //and split it into smaller chunks
    $attachment = chunk_split(base64_encode(file_get_contents('img.pdf'))); 
    //define the body of the message. 
    ob_start(); //Turn on output buffering 
    ?> 
    --PHP-mixed-<?php echo $random_hash; ?>  
    Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>" 
     
    Content-Type: text/plain; charset="iso-8859-1"'."\n"; 
    Content-Transfer-Encoding: 8bit'; 
     
    Bonjour, 
    <?php 
    echo $_SESSION['userlogin']['id'];
    echo "<BR>";
    $Message = "<b>Texte en Gras</b><u>Texte Souligné</u><i>Texte en Italique</i>";
    echo $_SESSION['userlogin']['nom'];
    echo $_SESSION['userlogin']['prenom'];
    echo $_SESSION['userlogin']['email'];
    ?>
     
    --PHP-alt-<?php echo $random_hash; ?>  
     
    Content-Type: text/html; charset="iso-8859-1" 
    Content-Transfer-Encoding: 8bit
     
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
    </head>
    <body>
    <tr>test</tr>
    <tr>Nom : <?php echo $_SESSION['userlogin']['nom'];?></tr>
    <tr>Prénom : <?php echo $_SESSION['userlogin']['prenom'];?></tr>
    <tr>Numéro de commande : <?php echo $_SESSION['userlogin']['email'];?></tr>
    <</body>
    </html>
     
    --PHP-alt-<?php echo $random_hash; ?>-- 
     
    --PHP-mixed-<?php echo $random_hash; ?>  
     
    Content-Type: application/pdf; name="img.pdf"  
    Content-Transfer-Encoding: base64  
    Content-Disposition: attachment  
     
    <?php echo $attachment; ?> 
    --PHP-mixed-<?php echo $random_hash; ?>-- 
     
    <?php 
    //copy current buffer contents into $message variable and delete current output buffer 
    $message = ob_get_clean(); 
    //send the email 
    $mail_sent = @mail( $to, $subject, $message, $headers ); 
    //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
    echo $mail_sent ? "msg envoyé" : "Mail failed"; 
    ?>
    mail ke je recois:
    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
    Bonjour,
    
    592<BR>coucou14901829.88--PHP-alt-a107456854363e412d31479e2671af28
    Content-Type: text/html; charset="iso-8859-1"
    Content-Transfer-Encoding: 8bit
    echo "<html>";
    <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    </head>
    <body>echo "<tr>Bonjour</tr>";
    <tr>test</tr>
    <tr>Nom :moi</tr>
    <tr>Prénom : coucou</tr>
    <tr>Numéro de commande : coucou</tr>
    </body>
    echo "</html>";
    --PHP-alt-a107456854363e412d31479e2671af28--
    je sais pas pk les balises d html s affiche et aussi le code en php?
    Merci de votre aide

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    C'est une sacrée bouillie ton code :

    La par exemple il manque le premier guillemet
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    $to = <a href="mailto:moi@gmail.com">moi@gmail.com</a>';
    La tu fais une concatenation de chaines alors que tu n'es plus dans les balises PHP :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Content-Type: text/plain; charset="iso-8859-1"'."\n";
    La tu as deux balises ouvrantes :
    Bref, reprend ton code, commence par le mettre en forme, relis le calmement car il y surement d'autres petites choses comme ca.

Discussions similaires

  1. [phpMyAdmin] [phpMyAdmin 2.8.1] probleme avec config.inc.php
    Par Vincent20100 dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 15
    Dernier message: 14/04/2008, 12h19
  2. Réponses: 14
    Dernier message: 24/08/2006, 18h12
  3. [Mail] probleme avec mail()
    Par eon-of-the-scorn dans le forum Langage
    Réponses: 2
    Dernier message: 31/07/2006, 10h29
  4. [Mail] probleme avec mail();
    Par pierrot10 dans le forum Langage
    Réponses: 3
    Dernier message: 24/04/2006, 15h46

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