如何使用 PEAR 邮件发送 html 邮件 [英] how to send html mails using PEAR mail

查看:28
本文介绍了如何使用 PEAR 邮件发送 html 邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PEAR 邮件系统发送经过身份验证的邮件.我需要发送带有链接的 HTML 邮件.在我开始使用 PEAR 邮件之前它工作正常.现在我无法发送 HTML 邮件.

I am using PEAR mail system to send authenticated mails.I need to send HTML mails that has alinks.It was working fine before i started using PEAR mail.Now i am not able to send HTML mails.

邮件正文如下所示:

$body = <<<EOD

Hiya $username

You might be interested in the current 'haves' and 'wants' on example.com

Latest Haves
<a href="http://www.exmaple.com/product/have/64/Titan+Fast+Track+SunGlass">Titan Fast Track SunGlass</a>

EOD;

一个标签出现在邮件中.你知道如何解决这个问题吗?请帮忙..

a tag appears as it is in the mail.Any idea how to solve this??Pls help..

推荐答案

如果你遵循这个例子,它就没有理由不工作:

If you follow this example there's no reason it shouldn't work:

<?php
include('Mail.php');
include('Mail/mime.php');

// Constructing the email
$sender = "Leigh <leigh@no_spam.net>";// Your name and email address
$recipient = "Leigh <leigh@no_spam.net>"; // The Recipients name and email address
$subject = "Test Email";// Subject for the email
$text = 'This is a text message.';// Text version of the email
$html = '<html><body><p>HTML message</p></body></html>';// HTML version of the email
$crlf = "
";
$headers = array('From' => $sender, 'Return-Path' => $sender, 'Subject' => $subject);

// Creating the Mime message
$mime = new Mail_mime($crlf);

// Setting the body of the email
$mime->setTXTBody($text);
$mime->setHTMLBody($html);

$body = $mime->get();
$headers = $mime->headers($headers);

// Sending the email
$mail =& Mail::factory('mail');
$mail->send($recipient, $headers, $body);
?>

注意:为了使上面的示例工作,除了 Pear Mail 之外,还需要 Pear Mail Mime Package.您可以在此处获取包 https://pear.php.net/package/Mail_Mime/download.

NOTE: in order for the above example to work one needs the Pear Mail Mime Package in addition the Pear Mail one. You can get the package here https://pear.php.net/package/Mail_Mime/download.

这篇关于如何使用 PEAR 邮件发送 html 邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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