php
  • email
  • 2012-08-16 3 views 7 likes 
    7

    PHP를 사용하고이 코드를 전자 메일로 일반 텍스트로 수신했는데 뭔가 놓쳤습니까? 예를 들어 링크가 포함될 수있는 형식화 된 전자 메일을 보내야합니다.PHP 메일 html 형식이 작동하지 않습니다.

    $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"을 헤더의 줄 끝으로 설정하는 것입니다.

    관련 문제