0

我有这个 PHP 代码/函数来发送电子邮件。

我需要添加什么代码来制作发送 HTML 而不是纯文本的电子邮件?

function sendemail($email_to,$email_from,$email_subject,$email_body,$email_replyto)
    {
        require_once "/usr/local/lib/php/Mail.php";

        $from = $email_from;
        $to = $email_to;
        $subject = $email_subject;
        $body = $email_body;

        $host = "mail.integradigital.co.uk";
        $username = "sending@integradigital.co.uk";
        $password = "*********";

        $headers = array ('From' => $from,
          'To' => $to,
          'Subject' => $subject);
        $smtp = Mail::factory('smtp',
          array ('host' => $host,
         'auth' => true,
         'username' => $username,
         'password' => $password));

        $mail = $smtp->send($to, $headers, $body);

        if (PEAR::isError($mail)) {
          echo("<p>" . $mail->getMessage() . "</p>");
         } else {
          echo("<p>Message successfully sent!</p>");
         }
    }
4

3 回答 3

1

添加"Content-Type: text/html; charset=ISO-8859-1\r\n";到您的标题。

于 2013-08-02T13:48:08.837 回答
0
<?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);
?>

请参阅链接 http://php.net/manual/en/function.mail.php

于 2013-08-02T13:59:01.383 回答
0

您最好使用Mail_Mime允许您轻松发送 HTML 和纯文本电子邮件的软件包:-

$mime = new Mail_mime();
$mime->setTXTBody($text);
$mime->setHTMLBody($html);

这是文档中的一个很好的例子

于 2013-08-02T14:03:11.060 回答