简体   繁体   English

PHP的邮件功能弄乱了我的电子邮件CSS

[英]php mail function messes my email css

I use a simple email function and it messes all my css.. it puts all the divs one below another instead of in the wrapper div.. is there a way to overcome it? 我使用了一个简单的电子邮件功能,它弄乱了我的所有CSS。它将所有div放在另一个div之下,而不是放在包装div中。是否有办法克服它?

 function email_template($app_link, $img_link, $app_name){
       $message='<html>
        <head>

    <title>Purchase Successful!</title>
         </head>
            <body>

      <div id="pic" style="position:relative; text-align:center; margin:0px auto;width:320px; height: 480px;">
       <a href="http://1111111111111edapps.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://1111111111111edapps.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 1111111111111edApps.com</a>
        </div>
       <img src="http://1111111111111edapps.com/email/images/1111111111111edAppEmail.jpg"/>
    </div>
       </body>
   </html>';

  return $message;


 }

The email function works.. but the divs should be inside ..pic div..but they are outside it.. Is there a way to deliver the email and have it being rendered the same as when i test it on a regular page? 电子邮件功能可以工作..但是div应该在..pic div ..内,但是它们在外面。.有没有一种方法可以传递电子邮件并使其呈现与在常规页面上进行测试时相同的形式?

Extra note: my php: 额外说明:我的php:

     $to = /*TO EMAIL ADDRESS*/"";
 $subject = "Hi!";
$body=email_template('http://1111111111111edapps.com/app_dl.php?app_id=34', $app_pic, $app_name);
echo $body;
 $headers  = 'MIME-Version: 1.0' . "\r\n";
 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 if (mail($to, $subject, $body,$headers)) {
   echo("<p>Message successfully sent!</p>");
  } else {
   echo("<p>Message delivery failed...</p>");
  }
  }

I ran your code through the W3C markup validator, and it seems that you may need to reconsider your approach here: 我通过W3C标记验证器运行了您的代码,看来您可能需要在这里重新考虑您的方法:

<a href="http://1111111111111edapps.com">
<div id="logo" style="position:absolute; width:130px; height:35px; z-index:99999;top:5;">
</div>
</a>

Put an inline element inside the a element (such as a span with display: block; applied). 将内联元素放在元素内(例如,具有display:block的跨度;已应用)。 I'd be willing to wager (at this moment in time) that the illegal div is causing you some issues. 我愿意打赌(此时此刻)非法div正在给您造成一些问题。

Remember, email clients aren't designed to handle HTML errors as well as web browsers do, and while support in some clients is very good, others can be quite far behind (I'm looking at you, Outlook 2007+). 请记住,电子邮件客户端的设计不像Web浏览器那样处理HTML错误,尽管某些客户端的支持非常好,但其他客户端的支持却远远落后(我正在研究的是Outlook 2007+)。

You didn't mention which email clients you'd tested and which were giving you the problems, so if correcting your markup doesn't fix it, give us a little more info. 您没有提及您测试过的电子邮件客户端以及给您带来问题的电子邮件,因此,如果更正标记无法解决问题,请向我们提供更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM