2012-08-16 14 views
7

PHP का उपयोग करके, और इस कोड के साथ मुझे एक सादा पाठ के रूप में ईमेल प्राप्त होता है, क्या मुझे कुछ याद आया? क्योंकि मुझे स्वरूपित ईमेल भेजने की आवश्यकता है जिसमें उदाहरण के लिए लिंक हो सकते हैं।PHP मेल एचटीएमएल प्रारूप काम नहीं कर रहा है

$to = "[email protected]"; 
$subject = "Password Recovery"; 

$body = ' 
<html> 
    <head> 
     <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
     <title>Birthday Reminders for August</title> 
    </head> 
    <body> 
     <p>Here are the birthdays upcoming in August!</p> 
     <table> 
      <tr> 
       <th>Person</th><th>Day</th><th>Month</th><th>Year</th> 
      </tr> 
      <tr> 
       <td>Joe</td><td>3rd</td><td>August</td><td>1970</td> 
      </tr> 
      <tr> 
       <td>Sally</td><td>17th</td><td>August</td><td>1973</td> 
      </tr> 
     </table> 
    </body> 
</html> 
'; 

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
$headers = "From: [email protected]\r\n"."X-Mailer: php"; 
if (mail($to, $subject, $body, $headers)) 
echo "Password recovery instructions been sent to your email<br>"; 

उत्तर

10

इस उदाहरण को देखें, यह PHP में मेल भेजने के लिए पर्याप्त है:

<?php 
    //change this to your email. 
    $to = "[email protected]"; 
    $from = "[email protected]"; 
    $subject = "Hello! This is HTML email"; 

    //begin of HTML message 
    $message =" 
<html> 
    <body> 
    <p style=\"text-align:center;height:100px;background-color:#abc;border:1px solid #456;border-radius:3px;padding:10px;\"> 
     <b>I am receiving HTML email</b> 
     <br/><br/><br/><a style=\"text-decoration:none;color:#246;\" href=\"www.example.com\">example</a> 
    </p> 
    <br/><br/>Now you Can send HTML Email 
    </body> 
</html>"; 
    //end of message 
    $headers = "From: $from\r\n"; 
    $headers .= "Content-type: text/html\r\n"; 

    //options to send to cc+bcc 
    //$headers .= "Cc: [email][email protected][/email]"; 
    //$headers .= "Bcc: [email][email protected][/email]"; 

    // now lets send the email. 
    mail($to, $subject, $message, $headers); 

    echo "Message has been sent....!"; 
?> 
+3

कृपया इसे उत्तर या अपवॉट के रूप में चिह्नित करें 'यदि यह सही है'। – GLES

18

अपने हेडर आप फिर से निर्धारित किया है:

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
$headers = "From: [email protected]\r\n"."X-Mailer: php"; 

आपको लगता है कि अंतिम पंक्ति में एक बिंदु है, जो भूल रहे हैं पर-लेखन पिछले दो:

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
$headers .= "From: [email protected]\r\n"."X-Mailer: php"; 
+0

... अच्छा पकड़ ... – j08691

+0

@andrewsi धन्यवाद मुझे लापता होने में भी इसी तरह की समस्या थी। – Muk

2

मुझे एक विशिष्ट मेल सर्वर के साथ एक ही समस्या मिली, मेरे मामले में समाधान हेडर के लिए लाइन के अंत के रूप में "\ r \ n" के बजाय "\ n" सेट करना था।

संबंधित मुद्दे