PHP消息体看起来分散

时间:2017-10-26 01:03:39

标签: php html css

我被卡住了,不知道我做错了什么,我做了一个简单的PHP邮件脚本,它发送正常但我在localhost上创建的内容与我上传到我的服务器时在收件箱中看到的不同并运行测试。注意:我在嵌入电子邮件脚本之前创建了原始表单。 THIS IS WHAT I CREATED,这是我在运行测试WHAT I GET IN EMAIL INBOX AS RESULT时在电子邮件收件箱中收到的内容。请问我做错了什么。

     $emailTo = $receiver;  
$emailFrom = $sender;

$emailSubject = "Receipt from Zuwi int'l company Ltd [$r_reference]";

if($data['success'] == true){


$message = '<html><body>'; //I CREATED THIS MESSAGE BODY IN HTML, WORKS WELL BUT MALFUNCTIONING ON EMAIL
$message .= '<div style="width:100%;margin-top:7%;"><div align="center"><h1 style="font-size:1.3em!important;margin-bottom:15px!important;"><img src="https://www.ogafriday.com/images/zuwii.jpg" alt="Password Change" style="height:40px;width:40px;" /></h1><small style="font-size: 12px;     color: #555555;  line-height: 14px; font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;">If you have any issues with this payment, kindly reply to this email or send an email to <br/><a href="mailto:store@ogafriday.com" target="_blank" style="color:#50a1f7;">store@ogafriday</a></small><h1>';
$message .= '<div style="width:510px;border:0.5px solid #ededed;margin-top:25px;height:510px;"><div style="height:180px;  background: #d14836;"><div align="center" style="position:absolute;width:40%;margin-top:50px;"><p style="    margin: 0 auto;     max-width: 300px;     font-size: 18px;  color:#fff;   line-height: 18px;     text-align: center;       font-family: -apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;">Zuwi int"l company Ltd received an outstanding unpaid invoice for</p><br/><h1 style="  margin: 0 auto;     max-width: 300px;     font-size: 36px;  color:#fff;   line-height: 18px;     text-align: center;  font-weight:bold;     font-family: -apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;">NGN 12,000.00</h1></div></div><p style="word-wrap: break-word!important;margin-bottom:-8px!important;font-size:14px;font-family:Verdana;"><b style="color:#555555;">Transaction Details</b> </p><br/>';
$message .= '<table rules="all" style="border-color: #dbdbdb;" cellpadding="10">';
$message .='<tr><td> </td></tr><br/><div style="margin-top:10px;position:absolute;margin-left:2%;margin-right:2%;border-bottom:0.5px solid #ededed;width:33%;padding-bottom:32px;"><div style="margin-left:0px;position:absolute;color:#555555;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;"> Reference </div> <div style="margin-left:65%;position:absolute;width:50%;color:#555555;font-weight:bold;position:absolute;width:50%;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;">'.$r_reference.'</div></div><br/><div style="margin-top:45px;position:absolute;margin-left:2%;margin-right:2%;border-bottom:0.5px solid #ededed;width:33%;padding-bottom:35px;"><div style="margin-left:0px;position:absolute;color:#555555;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;"> Date </div> <div style="margin-left:65%;position:absolute;width:50%;color:#555555;font-weight:bold;position:absolute;width:50%;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;"> '.$r_date.' </div></div><br/><div style="margin-top:85px;position:absolute;margin-left:2%;margin-right:2%;border-bottom:0.5px solid #ededed;width:33%;padding-bottom:40px;"><div style="margin-left:0px;position:absolute;color:#555555;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;"> Method </div> <div style="margin-left:62%;color:#555555;font-weight:bold;position:absolute;width:50%;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;">Pay on delivery </div></div>';
$message .= '<div style="margin-top:33%;"><p style="font-size: 16px;     color: #555555;  line-height: 14px; font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;">Zuwi intl company Ltd</p> <p style="margin-top:-10px;"><a href="mailto:store@ogafriday.com" target="_blank" style="color:#50a1f7;font-size:14px;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;">store@ogafriday</a></p></div></div></div></div>';
$message .= "</table>";
$message .= "</body></html>";


$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html; charset=utf-8" . "\r\n"; 
$headers .= "From: <$emailFrom>" . "\r\n";
mail($emailTo, $emailSubject, $message, $headers);

$data['success'] = true;

json_encode($data);

1 个答案:

答案 0 :(得分:1)

将代码转换为表格结构然后它将起作用。我现在只需将代码更改为表格格式,即可随意添加样式。

浏览器视图

enter image description here

<强>记住 为了获得最佳视图,请使用电子邮件模板的表结构。

$message = '<html><body>'; //I CREATED THIS MESSAGE BODY IN HTML, WORKS WELL BUT MALFUNCTIONING ON EMAIL
$message .= '<table style="width:100%;margin-top:7%;"><tr><td><div align="center"><h1 style="font-size:1.3em!important;margin-bottom:15px!important;"><img src="https://www.ogafriday.com/images/zuwii.jpg" alt="Password Change" style="height:40px;width:40px;" /></h1><small style="font-size: 12px;     color: #555555;  line-height: 14px; font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;">If you have any issues with this payment, kindly reply to this email or send an email to <br/><a href="mailto:store@ogafriday.com" target="_blank" style="color:#50a1f7;">store@ogafriday</a></small><h1>';
$message .= '<div style="width:510px;border:0.5px solid #ededed;margin-top:25px;height:510px;"><div style="height:180px;  background: #d14836;"><br><p style=" margin: 0 auto; max-width: 300px;     font-size: 18px;  color:#fff;   line-height: 18px;     text-align: center; font-family: -apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;">Zuwi int"l company Ltd received an outstanding unpaid invoice for</p><br/><h1 style="  margin: 0 auto;     max-width: 300px;     font-size: 36px;  color:#fff;   line-height: 18px;     text-align: center;  font-weight:bold;     font-family: -apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;">NGN 12,000.00</h1></div><p style="word-wrap: break-word!important;margin-bottom:-8px!important;font-size:14px;font-family:Verdana;"><b style="color:#555555;">Transaction Details</b> </p><br/>';
$message .= '<table width="90%" style="margin:0px auto;" border="0" cellpadding="10" cellspacing="0">
    <tr>
        <td style="border-bottom:1px solid #ddd;">Reference</td>
        <td style="border-bottom:1px solid #ddd;" align="right">You text</td>
    </tr>
    <tr>
        <td style="border-bottom:1px solid #ddd;">Date</td>
        <td style="border-bottom:1px solid #ddd;" align="right">You text</td>
    </tr>
    <tr>
        <td style="border-bottom:1px solid #ddd;">Method</td>
        <td style="border-bottom:1px solid #ddd;" align="right">You text</td>
    </tr>
    <tr>
        <td align="center" colspan="2"><br><p>Zuwi intl company Ltd</p><a href="mailto:store@ogafriday">store@ogafriday</a></td>
    </tr>
    <tr>
        <td align="center" colspan="2"></td>
    </tr>
</table>';
$message .= "</td></tr></table></body></html>";