1

我正在尝试创建一个自动回复电子邮件,内容是一个 PHP 变量。我希望它输出 HTML 代码,但现在不是。

//Example:
$respondmessage = " Hello $fullname,
 We are confirming your Appointment today!
Please <a href="http://yourlink.com/">click here to confirm</a>!
";

这输出:

Hello Your Name,
 We are confirming your Appointment today!
Please <a href="http://yourlink.com/">click here to confirm</a>!

在电子邮件中。有没有办法让电子邮件接受 HTML 代码?

4

3 回答 3

0

You can following line as an header in your code :

$headers = "Content-type: text/html\r\n";

This will help you to create email into HTML

于 2013-06-13T19:50:42.930 回答
0

You have to include this header to your email script

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";    

From http://php.net/manual/en/function.mail.php example# 4

<?php

// multiple recipients
$to = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';

// 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>Joe</td><td>3rd</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' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

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

// Mail it
mail($to, $subject, $message, $headers);
?>
于 2013-06-13T19:50:43.600 回答
0

mail假设您正在使用PHP中的内置函数:

<?php
// multiple recipients
$to  = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';

// 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>Joe</td><td>3rd</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' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?>

这个例子来自:http ://us2.php.net/manual/en/function.mail.php

重要的部分是$headers变量。

顺便说一句,正如 andrewsi 提到的 - 你需要逃避你的报价:

$respondmessage = "Hello $fullname,
    We are confirming your Appointment today!
    Please <a href=\"http://yourlink.com/\">click here to confirm</a>!";
于 2013-06-13T19:49:34.727 回答