首页 > 解决方案 > 如何显示我的 html 邮件?

问题描述

我正在为一个发送自动电子邮件(和其他一些东西)的学校项目编写代码。

我认为编写 html 电子邮件是个好主意,所以我就这样做了,但后来我发现发送电子邮件时,它只包含标题和标题。

我已经尝试过 php.ini,但这并不好,因为我使用的是学校的 FTP 服务器,而且我没有权限做那种事情。


下面的代码是我的 php 的特定部分。

<?php
  $headers  = "MIME-Version: 1.0\r\n";
  $headers .= "Content-type: text/html; charset=ISO-8859-1\r\n";
  $headers .= "From: ymackor <noreply.ymackor@gmail.com>\r\n";
  $headers .= "BCC: noreply.ymackor@gmail.com\r\n";

  $message  = "<html><head><style>table{border-collapse:collapse;border:2px solid black;}tr,td{border-width:1px 0;border-style:solid;border-color:dimgray;padding:0 10px;border-left:.5px solid lightgray;border-right:.5px solid lightgray;text-align:left;style></head><body>";
  $message .= "<h2>Your order is handled and sent, it will arrive in 12 hours:</h2>";
  $message .= "<table> <tr> <th> Product </th> <th> Quantity </th> <th> Price </th> </tr>";
  foreach ($product as $i => $x) {
    $message .= "<tr> <td> " . $product_name[$i] . " </td> <td> " . $x . " </td> <td> " . money_format("%^#10.2n", $product_price[$i]) . " </td> </tr>";
  }
  $message .= "<tr> <th> <u>Total:</u> </th> <th> " . array_sum($product) . " </th> <th> " . money_format("%^#10.2n", array_sum($product_price));
  $message .= "</table>";
  $message .= "</body></html>";

  mail($_POST["email"], "NO-REPLY: Your order", $message, $headers);
?>

这是我的电子邮件源代码:

Delivered-To: yannick.mackor@gmail.com
Received: by 2002:a6b:7110:0:0:0:0:0 with SMTP id q16-v6csp459335iog;
        Mon, 25 Jun 2018 02:37:59 -0700 (PDT)
X-Google-Smtp-Source: ADUXVKIPxPM3xq+h6PvxFCto0awYtGAIWLE+HLAWmZA2IWQJe7wA2w8LqLGsAEfNPc0iFt3leNeC
X-Received: by 2002:a50:96d1:: with SMTP id z17-v6mr10591217eda.55.1529919479460;
        Mon, 25 Jun 2018 02:37:59 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1529919479; cv=none;
        d=google.com; s=arc-20160816;
        b=anlEjH3PMUMyGvY2jLrIDXs+frMsdSb8zmigcgmxybAEQPv+yxiM9GPfI0nM1La+iZ
         shqeg1I/efpMdOx2bLpqaQfctSAL+kerh0ISFBIg9ojnN1JVpkVZxIzNOGmelPFSGODV
         NkAvsKKKC0yIUuTNvsLg+4sCJ3aGnaElrdMsIp0hhNmdZxbSq2AtBu9vQnpvw3eAVG3h
         JaVISgiq1SOYlSACKLbPpN7TeyIzmYRjWMPZimmAoLW2u81hH6Qeb2sZfbFLkL8OClJx
         zrNIVbkxzVnANtEBioWKWEjA0KxXcgflJjjp8796H+hCHkZYdBGHfZWMQ3i/7vxFc3kQ
         grUQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=date:sender:message-id:from:mime-version:subject:to
         :arc-authentication-results;
        bh=PYQtoENArjkziK1+qiQVdq1Wz83XImd871/k1vmO/XM=;
        b=j4esNHXiikbTqzvS1GPcZKqbMRPUNvpk99OKjxBLnIszLMyr+USRLYAWyc8YMH1W4l
         PtktDEROGgxLZvp6nLhumBMlF2QWZuMdbH2wyvuTnuDaAJCH1haHTaeaLw05yK4mDLSu
         YgyzFXU3hDSH07F5hXx3GjaWh49e6Edh+WXz6s1ocCN2qDKzFHPQmrXBHLMufqlrvWXT
         8tE0wFaQ0Sbx1daXX0NIMVvLIrE3GXcla+0Nc8BbqlOK+TGhT0HDGZgZ/UAhqMwZQP73
         FJPds4DaxF2iOXOtTPae3tu0+GJvOcbCfQS9c632kVeZvxJPCLpTQ6eiToSCmeGBc7FU
         fFEA==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=pass (google.com: best guess record for domain of cals@da01.informatica-cals.nl designates 87.233.228.82 as permitted sender) smtp.mailfrom=cals@da01.informatica-cals.nl;
       dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com
Return-Path: <cals@da01.informatica-cals.nl>
Received: from da01.informatica-cals.nl (da01.informatica-cals.nl. [87.233.228.82])
        by mx.google.com with ESMTPS id n12-v6si977002edr.216.2018.06.25.02.37.59
        (version=TLS1 cipher=AES128-SHA bits=128/128);
        Mon, 25 Jun 2018 02:37:59 -0700 (PDT)
Received-SPF: pass (google.com: best guess record for domain of cals@da01.informatica-cals.nl designates 87.233.228.82 as permitted sender) client-ip=87.233.228.82;
Authentication-Results: mx.google.com;
       spf=pass (google.com: best guess record for domain of cals@da01.informatica-cals.nl designates 87.233.228.82 as permitted sender) smtp.mailfrom=cals@da01.informatica-cals.nl;
       dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com
Received: from cals by da01.informatica-cals.nl with local (Exim 4.80.1) (envelope-from <cals@da01.informatica-cals.nl>) id 1fXNwd-0001xF-45; Mon, 25 Jun 2018 11:37:59 +0200
To: yannick.mackor@gmail.com
Subject: NO-REPLY: Your order
X-PHP-Script: informatica-cals.nl/ymackor/webshop/bestelform.php for 83.128.169.172
MIME-Version: 1.0
Content-type: text/html; charset=ISO-8859-1
From: ymackor <noreply.ymackor@gmail.com>
X-Mailer: PHP/5.2.17
Message-Id: <E1fXNwd-0001xF-45@da01.informatica-cals.nl>
Sender: <cals@da01.informatica-cals.nl>
Date: Mon, 25 Jun 2018 11:37:59 +0200

<html><head><style>table{border-collapse:collapse;border:2px solid black;}tr,td{border-width:1px 0;border-style:solid;border-color:dimgray;padding:0 10px;border-left:.5px solid lightgray;border-right:.5px solid lightgray;text-align:left;style></head><body><h2>Your order is handled and sent, it will arrive in 12 hours:</h2><table> <tr> <th> Product </th> <th> Quantity </th> <th> Price </th> </tr><tr> <td> Ice popsicle </td> <td> 10 </td> <td>  $         0.95 </td> </tr><tr> <td> Hot chocolate </td> <td> 12 </td> <td>  $         9.50 </td> </tr><tr> <td> Self-destructing alarm clock </td> <td> 13 </td> <td>  $       115.00 </td> </tr><tr> <th> <u>Total:</u> </th> <th> 35 </th> <th>  $       125.45</table></body></html>

标签: phphtml-email

解决方案


您的代码应该可以工作,看起来代码没有问题,但是使用 PHP 配置或邮件配置。我还推荐使用 PHPMailer,因为它实际上给你很好的状态反馈,而且它是面向对象的。

您可以在 SSH 上运行 mail 命令,以查看它是否可以通过该命令运行。


推荐阅读