简体   繁体   English

如何显示我的HTML邮件?

[英]How do I display my html mail?

I am writing a code for a school project that sends an automatic email (and some other things). 我正在为一个学校项目编写代码,该项目发送自动电子邮件(和其他一些东西)。

I thought that it would be a good idea to write an html-email so I did that, but then I found that when the email is sent, it contains nothing but the title and the headers. 我认为写一个html电子邮件是个好主意,所以我做到了,但是后来我发现,发送电子邮件时,除了标题和标头外,它什么都没有。

I already tried php.ini, but that's no good, since I'm using the FTP-server of my school and I don't have permission to do that kind of things. 我已经尝试过php.ini,但这不好,因为我使用的是学校的FTP服务器,而且我没有这样做的权限。


The code underneath is the particular part of my php that this is about. 下面的代码是我的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);
?>

and this is my email sourcecode: 这是我的电子邮件源代码:

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>

Your code should work, it looks like there's nothing wrong with the code, but with PHP Configuration or Mail configuration. 您的代码应该可以工作,看起来没有问题,但是使用PHP Configuration或Mail配置。 I also recommend using PHPMailer since it actually gives you nice status feedback and it is object oriented. 我还建议使用PHPMailer,因为它实际上可以为您提供良好的状态反馈,并且它是面向对象的。

You could run the mail command on SSH just to see if it works through the command. 您可以在SSH上运行mail命令,只是查看它是否可以通过该命令运行。

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

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