发送电子邮件失败..用PHP功能

时间:2012-05-21 14:16:59

标签: php email

我的电子邮件方法有效:

   <?php
     $to = "eddy2012@gmail.com";
     $subject = "Hi!";
    $body=email_template('http://zzzzedapps.com/app_dl.php?app_id=34', $app_pic, $app_name);
    echo $body;
     $headers = 'From: info@zzzzedapps.com' . "\r\n" .
        'Reply-To: info@zzzzedapps.com' . "\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>");
      }
     ?>

但是当我使用这个函数来设置body变量..:

   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 个答案:

答案 0 :(得分:1)

您正在使用php的mail功能发送html邮件,请查看手册,具体如下:

// To send HTML mail, the Content-type header must be set
示例#4中的

我也很确定你需要摆脱doctype