doushan7077 2017-03-11 02:44
浏览 140
已采纳

在通过php发送HTML电子邮件时,将php字符串存储在php字符串中是一个好主意

Some email providers like gmail do not support css classes when sending html email through php, so I thought i would store css classes or even full codes in php strings so I can use them multiple times. For example

    $leftbox = '<div style="background:#333;border:1px solid #000;padding:5px 2px;float:left;width:200px;">';
$rightbox = '<div style="background:#FFF;border:1px solid #CCC;padding:5px 2px;float:right;width:200px;">';

$headers  = 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";

$message = '<html><body style="background:#000;margin:auto;width:400px;">';
$message .= $leftbox.'Name </div>'.$rightbox.' Content 1</div>';
$message .= $leftbox.'Addresss </div>'.$rightbox.' Content 2</div>';
$message .= $leftbox.'Mobile </div>'.$rightbox.' Content 3</div>';

mail("emailadress@email.com", "Subject", $message, $headers);

Is this a good idea, or is there any other good ways to do this if you want a good looking html email sent with php?

  • 写回答

1条回答 默认 最新

  • dongliuxia9495 2017-03-11 02:51
    关注

    What is wrong with an inline style sheet? For example:

    <!DOCTYPE html><html>
    <head>
    <style type="text/css">
    body {
        background:#000;
        margin:auto;
        width:400px 
    } 
    .leftBox {
        background:#333;
        border:1px solid #000;
        padding:5px 2px;
        float:left;
        width:200px
    }
    </style>
    </head>
    <body>
    <div class="leftBox">Something in the left box</div>
    </body>
    </html>
    

    Edit: Just had a look at some HTML email on 'Inbox' and you may need to include a <!DOCTYPE html>tag. Other than that, the above code "works for me".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划