2012-05-21 54 views
0

我有電子郵件方法的工作原理:發送電子郵件失敗。與PHP函數

<?php 
    $to = "[email protected]"; 
    $subject = "Hi!"; 
    $body=email_template('http://zzzzedapps.com/app_dl.php?app_id=34', $app_pic, $app_name); 
    echo $body; 
    $headers = 'From: [email protected]' . "\r\n" . 
     'Reply-To: [email protected]' . "\r\n" . 
     'X-Mailer: PHP/' . phpversion(); 
    if (mail($to, $subject, $body,$headers)) { 
     echo("<p>Message successfully sent!</p>"); 
     } else { 
     echo("<p>Message delivery failed...</p>"); 
     } 
    ?> 

但是當我使用這個功能來定身變..:

function email_template($app_link, $img_link, $app_name){ 
     $message=' 
      <html xmlns="http://www.w3.org/1999/xhtml"> 
      <head> 
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
      </head> 
      <body> 

     <div id="pic" style="position:relative; text-align:center; margin:0px auto;width:320px; height: 480px;"> 
     <a href="http://zzzzedapps.com"> 
     <div id="logo" style="position:absolute; width:130px; height:35px; z-index:99999;top:5;"> 
     </div> 
     </a> 
     <div id="clickHere" style=" position:absolute;width:320px;height:50px;z-index:99999;top:60px;text-align: center;"> 
      <span id="clickHereText" style="font-size:140%; color:white;"> <a href="'.$app_link.'" style="color:yellow">Click Here</a> to Download<br/> 
       your phonemate app 
       </span> 
     </div> 

     <div id="appImg" style="position:absolute;width:50px; height:50px;z-index:99999; left:50px;top:210px;"> 
      <img src="http://zzzzedapps.com/'.$img_link.'" width="53px" height="53px"/> 
     </div> 
     <div id="appLabel" style="position:absolute; width:50px; height:10px; z-index:99999; text-align: center; left:50px; top:260px;"> 
      <span style="color:white; font-size: 50%;">'.$app_name.'</span> 
     </div> 

     <div id="downloadLink" style="position:absolute; width:320px; height:30px; z-index:99999; bottom:0px; text-align: center;"> 
      <a href="'.$app_link.'" style="color:yellow">Download our app on zzzzedApps.com</a> 
     </div> 
     <img src="http://zzzzedapps.com/email/images/zzzzedAppEmail.jpg"/> 
    </div> 
     </body> 
    </html>'; 

    return $message; 
} 

它不能發送電子郵件。

這種失敗:

$body=email_template('http://zzzzedapps.com/app_dl.php?app_id=34', $app_pic, $app_name); 

雖然身體被成功呼應?

我在哪裏有bug ..我如何克服它?

+1

_「它無法發送電子郵件。」_任何錯誤,日誌? – CodeCaster

+0

我沒有一個日誌..但沒有..回聲成功交付...當劇本完成 –

+0

好吧,我設法發送一個..但它到達僅作爲文本 –

回答

1

您正在使用PHP的mail函數發送HTML郵件,查手冊,具體是:

// To send HTML mail, the Content-type header must be set 

在例如#4。我也很確定你需要擺脫doctype

+0

我該離開什麼呢? html和body? –

+0

@Dmitry Makovetskiyd是的,並設置正確的內容類型。 – jeroen

+0

看到我的更新...什麼內容類型應該只是HTML? –