简体   繁体   中英

How to build a format for email body with HTML sent with PHP

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 $message area?

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));
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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