2014-02-20 158 views
0

試圖爲我的成員做一個模板郵件,但是當它通過管理區域發送時我在OutLook中查找它只是html代碼,任何人都可以幫忙嗎?我認爲大部分情況是正確的,但也許標題是錯誤的?HTML PHP郵件不能正常工作

$check2 = mysql_query("SELECT * FROM users WHERE username='$_POST[users]'"); 
while ($display = mysql_fetch_array($check2)) { 
$id2 = $display['id']; 
$name2 = $display['name']; 
$username2 = $display['username']; 
$email2 = $display['email']; 


$subject2 = $_POST[subject]; 
$message2 = $_POST[message]; 
$from = "[email protected]"; 
$whofrom = "Email Newsletter"; 
$header = "From: ". $whofrom . " <" . $from . ">\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

     $mail_body = "<!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' /> 
<meta name='viewport' content='width=device-width, initial-scale=1.0'/> 
</head> 
<body style='margin: 0; padding: 0;'> 
    <table border='0' cellpadding='0' cellspacing='0' width='100%'> 
     <tr> 
      <td style='padding: 10px 0 30px 0;'> 
       <table align='center' border='0' cellpadding='0' cellspacing='0' width='600' height='100' style='border: 1px solid #cccccc; border-collapse: collapse;'> 
        <tr> 
         <td align='center' bgcolor='#CCCCCC' background='http://vcasts.tv/images/bg.jpg' style=' background-position:center; padding: 40px 0 30px 0; color: #153643; font-size: 28px; font-weight: bold; font-family: Arial, sans-serif;'> 
          <img src='http://domain.com/images/logo.png' /> 
         </td> 
        </tr> 
        <tr> 
         <td bgcolor='#ffffff' style='padding: 40px 30px 40px 30px;'> 
          <table border='0' cellpadding='0' cellspacing='0' width='100%'> 
           <tr> 
            <td style='color: #153643; font-family: Arial, sans-serif; font-size: 24px;'> 
             <b>Dear $name2</b> 
            </td> 
           </tr> 
           <tr> 
            <td style='padding: 20px 0 30px 0; color: #153643; font-family: Arial, sans-serif; font-size: 16px; line-height: 20px;'><p>$message2</p> 
            <p>================<br /> 
            Thank You,<br /> 

            Max B 
            </p></td> 
           </tr> 
          </table> 
         </td> 
        </tr> 
        <tr> 
         <td bgcolor='#E4E7ED' style='padding: 30px 30px 30px 30px;'> 
          <table border='0' cellpadding='0' cellspacing='0' width='100%'> 
           <tr> 
            <td style='color: #666; font-family: Arial, sans-serif; font-size: 14px;' width='75%'>Copyright © vCasts.tv 2013 - 2014. All Rights Reserved<br/></td> 
            <td align='right' width='25%'> 
             <table border='0' cellpadding='0' cellspacing='0'> 
              <tr> 
               <td style='font-family: Arial, sans-serif; font-size: 12px; font-weight: bold;'> 
                <a href='http://www.twitter.com/ccc' target='_blank' style='color: #ffffff;'> 
                <img src='http://domain.com/images/tww.png' alt='Twitter' width='38' height='38' style='display: block;' border='0' /> 
                </a> 
               </td> 
               <td style='font-size: 0; line-height: 0;' width='20'>&nbsp;</td> 
               <td style='font-family: Arial, sans-serif; font-size: 12px; font-weight: bold;'> 
                <a href='https://www.facebook.com/cccc' target='_blank' style='color: #ffffff;'> 
                 <img src='http://domain.com/images/fbb.png' alt='Facebook' width='38' height='38' style='display: block;' border='0' /> 
                </a> 
               </td> 
              </tr> 
             </table> 
            </td> 
           </tr> 
          </table> 
         </td> 
        </tr> 
       </table> 
      </td> 
     </tr> 
    </table> 
</body> 
</html> 

Sent: ".date("l jS \of F Y ", time()).""; 

     mail($email2, $subject2, $mail_body, $header) or die(""); 
     echo "<script type='text/javascript'>alert('Your email has been sent to: $username2!');</script>"; 
     }}}}} 

希望上面的代碼有幫助。 謝謝

+0

你看着你的PHP日誌? –

回答

1

你沒有理由額外s

$header = "From: ". $whofrom . " <" . $from . ">\r\n"; 
---> $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

刪除從$headers s,你沒事。

+0

謝謝你們,當我從標題中刪除s時,它們就能正常工作! – MBell86

0

您使用此兩個變量:

$header = "From: ". $whofrom . " <" . $from . ">\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

試試這個:

$header = "From: ". $whofrom . " <" . $from . ">\r\n"; 
$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
0
$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

更改爲

$header .= "Content-Type: text/html; charset=UTF-8\r\n";