我如何调整this answer并将其与允许我发送HTML邮件相结合?我有pear mail_mime
,我听说这与它有关。这是我到目前为止所获得的代码,但它不起作用:
require 'Mail.php';
require 'Mail/mime.php';
$userID = 13;
$realname = getRealName($userID); //This function works
require_once "mail_register.php"; // Includes $register_body_txt and $register_body_html
$subject = "DERP YAY SENT EMAIL!";
$to = '<myemail@me.com>';
$from = "Derp <noreply@derp.com>";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "noreply@derp.com";
$password = "password";
$crlf = '\n';
$headers = array (
'From' => $from,
'Subject' => $subject,
'Return-Path' => $from);
$mime = new Mail_mime(array('eol' => $crlf));
$mime->setTXTBody($register_body_txt);
$mime->setHTMLBody($register_body_html);
$body = $mime->get();
$headers = $mime->headers($headers);
$mail =& Mail::factory('mail');
$mail->send($to, $headers, $body);
if (PEAR::isError($mail)) { //This is no longer working. Before I adapted the previous script, it would show me actual errors instead of printing out successful all the time.
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}