如何为使用PHP发送的HTML构建电子邮件正文的格式 [英] How to build a format for email body with HTML sent with PHP

查看:87
本文介绍了如何为使用PHP发送的HTML构建电子邮件正文的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图了解如何自定义使用PHP发送的电子邮件。我相信它假设用基本的< html> 和表来完成。我在 $ message 区域做错了什么?



截至目前,我在我的消息区域得到这个信息:

  < html>< body>< h1> Hello,World!< / h1>< / body>< / html> 

以下是我的代码:

 <?php 
session_start();
require_once('payflow.php');

$ tranid = $ _GET ['PNREF'];
$ email = $ _GET ['EMAIL'];
$ billtofirstname = $ _GET ['BILLTOFIRSTNAME'];
$ billtolastname = $ _GET ['BILLTOLASTNAME'];
$ billtoname = $ _GET ['BILLTONAME'];
$ billtostreet = $ _GET ['BILLTOSTREET'];
$ billtostreet2 = $ _GET ['BILLTOSTREET2'];
$ billtocity = $ _GET ['BILLTOCITY'];
$ billtostate = $ _GET ['BILLTOSTATE'];
$ billtozip = $ _GET ['BILLTOZIP'];

$ to = $ email;
$ subject =ORDER#$ tranid\\\
;
$ headers =From:$ email\\\
;

$ message ='< html>< body>';
$ message。='< h1> Hello,World!< / h1>';
$ message。='< / body>< / html>';

邮件($ to,$ subject,$ message,$ headers);

?>

电子邮件效果很好, $ _ GET data is is精细。刚刚讨论如何让消息区读取< html>

解决方案

根据php文档,

 <?php 
//多个收件人
$到='johny@example.com,sally@example.com'; //注意逗号

//标题
$ subject ='八月的生日提醒';

//消息
$ message ='
< html>
< head>
< title>八月份的生日提醒< / title>
< / head>
< body>
< p>以下是八月即将到来的生日!< / p>
< table>
< tr>
第Person人第th日第th th月第th th第th年第th th月th th th th th th th th th th th th th th th月th th th th th th th th th th th th th th th th th月
< / tr>
< tr>
< td> Johny< / td>< td> 10th< / td>< td> August< / td>< td> 1970< / td>
< / tr>
< tr>
< td> Sally< / td>< td> 17th< / td>< td> August< / td>< td> 1973< / td>
< / tr>
< / table>
< / body>
< / html>
';

//要发送HTML邮件,Content-type头文件必须设置为
$ headers [] ='MIME-Version:1.0';
$ headers [] ='Content-type:text / html;字符集= ISO-8859-1’ ;

//附加标题
$标题[] ='致:Mary< mary@example.com>,Kelly< kelly@example.com>';
$ headers [] ='发件人:生日提醒< birthday@example.com>';
$ headers [] ='抄送:birthdayarchive@example.com';
$ headers [] ='密送:birthdaycheck@example.com';

//邮寄
邮件($ to,$ subject,$ message,implode(\r\\\
,$ headers));
?>


Trying to understand how to customize an email sent with PHP. I believe its suppose to be done with basic <html> and tables. What am I doing wrong in the $messagearea?

As of now I get this in my message area:

<html><body><h1>Hello, World!</h1></body></html>

Here is my code:

<?php
  session_start();
  require_once('payflow.php');

  $tranid  = $_GET['PNREF'];
  $email   = $_GET['EMAIL'];
  $billtofirstname = $_GET['BILLTOFIRSTNAME'];
  $billtolastname = $_GET['BILLTOLASTNAME'];
  $billtoname = $_GET['BILLTONAME'];
  $billtostreet = $_GET['BILLTOSTREET'];
  $billtostreet2 = $_GET['BILLTOSTREET2'];
  $billtocity = $_GET['BILLTOCITY'];
  $billtostate = $_GET['BILLTOSTATE'];
  $billtozip = $_GET['BILLTOZIP'];

  $to = $email;
  $subject = "ORDER #$tranid\n";
  $headers = "From: $email\n";

  $message = '<html><body>';
  $message .= '<h1>Hello, World!</h1>';
  $message .= '</body></html>';

  mail($to,$subject,$message,$headers);

?>

Email works well, $_GET data is fine. Just confussed on how to get the message area to read <html>

解决方案

As per php document,

<?php
// Multiple recipients
$to = 'johny@example.com, sally@example.com'; // note the comma

// Subject
$subject = 'Birthday Reminders for August';

// Message
$message = '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
    <tr>
      <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
    </tr>
    <tr>
      <td>Johny</td><td>10th</td><td>August</td><td>1970</td>
    </tr>
    <tr>
      <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
    </tr>
  </table>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';

// Additional headers
$headers[] = 'To: Mary <mary@example.com>, Kelly <kelly@example.com>';
$headers[] = 'From: Birthday Reminder <birthday@example.com>';
$headers[] = 'Cc: birthdayarchive@example.com';
$headers[] = 'Bcc: birthdaycheck@example.com';

// Mail it
mail($to, $subject, $message, implode("\r\n", $headers));
?>

这篇关于如何为使用PHP发送的HTML构建电子邮件正文的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆