2010-07-07 5 views
0

Je suis essayer d'envoyer un mail à partir de mon application php.Mail envoyer avec succès, mais le texte en texte clair qui contient html tags.is là une solution pour cela.S'il vous plaît m'aider.Mon message est comme suitFonction PHP Mail affiche les messages en texte brut dans la boîte de réception

$message = ' 
       <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
        <html xmlns="http://www.w3.org/1999/xhtml"> 
         <head> 
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
           <title>Gaishan</title> 
         </head> 
         <body> 
          <table width="750" border="0" cellspacing="0" cellpadding="0" style="background-color:#043c58; padding:15px;"> 
          <tr> 
           <td style="padding-bottom:10px;"><a href="#"><img src="http://www.toobler.com/staging/gaishan/index.php/users/ec/1/logo_mail.jpg"; border="0" /></a></td> 
          </tr> 
          <tr> 
           <td colspan="2" style="background-color:#fff; padding:10px 30px;"><h1 style="font-family:Arial, Helvetica, sans-serif; font-size:26px; font-weight:bold; color:#111;">testmail</h1> 
            <p style="font-family:Arial, Helvetica, sans-serif; font-size:14px; font-weight:normal; color:#555; line-height:22px;">http://www.toobler.com/</p> 
             <a href="http://www.toobler.com/" style="font-family:Arial, Helvetica, sans-serif; color:#7ea515; text-decoration:underline;">http://www.toobler.com/staging/gaishan/index.php/users/ec/1/'.time().'</a> 
             <p style="font-family:Arial, Helvetica, sans-serif; font-size:14px; font-weight:normal; color:#4a483f; line-height:22px;">Demo textDemo textDemo textDemo text</p> 
             <p style="font-family:Arial, Helvetica, sans-serif; font-size:14px; font-weight:normal; color:#4a483f; line-height:22px;">Demo textDemo textDemo textDemo textDemo text</p> 
             <br /> 
             <p style="font-family:Arial, Helvetica, sans-serif; font-size:14px; font-weight:normal; color:#4a483f; line-height:22px;">Demo textDemo textDemo text<br /> 
             Demo textDemo textDemo text Demo textDemo text 
             </p> 
           </td> 
          </tr> 
         </table> 
        </body> 
       </html> 
       '; 

Répondre

3

Définissez-vous également les en-têtes pour indiquer que l'e-mail est censé être HTML? Si vous ne le faites pas, ce sera toujours du texte brut.

// To send HTML mail, the Content-type header must be set 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

mail($to, $subject, $message, $headers); 
+1

D'accord, cependant le codage (charset) devrait être utf-8 car c'est celui contenu dans le html, je le crois. –

+0

Merci beaucoup.travers parfaitement – abhis

+0

Moritz tacheté +1 –

0

Vous devez définir: Type de contenu: text/html; dans l'en-tête du mail.

0

$ headers = 'Version MIME: 1.0'. "\ r \ n"; $ headers. = 'Type de contenu: text/html; jeu de caractères = iso-8859-1 '. "\ r \ n"; mail ($ à, $ sujet, $ message, $ en-têtes);

Questions connexes