如何发送HTML电子邮件?

时间:2011-06-14 09:10:05

标签: php pear

我需要发送html电子邮件。所以我使用PEAR libraryMail extension

所以我写了这段代码:

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

$email = "xxx@gmail.com";
$from_addr = "example <yyy@gmail.com>";
$message_subject ="Test";    
$text =  "
Hello.
This is a link:

http//:www.hardevent.net/index.php

byebye
";

$html = "<html>
<body>
<p>
Hellooooo, this is a link:
</p>
<a href=\"http://www.google.com\"/>Gooooo</a>
</body>
</html>";

                     $headers = array ("From" => $from_addr,
                                       "To" => $email,
                                       "Subject" => $message_subject);


                     $crlf = "\n";
                     $mime = new Mail_mime($crlf);
                     $mime->setTXTBody($text);
                     $mime->setHTMLBody($html);
                     $body = $mime->get();
                     $hdrs = $mime->headers($headers);
                     $smtp = Mail::factory("smtp", array ('host' => "smtp.xxx.com",
                                                          'auth' => true,
                                                          'username' => "xxx",
                                                          'password' => "xxx"));
                     $mail = $smtp->send($email, $hdrs, $body);

但这是我看到的电子邮件(只有没有链接的文字):

Object: Test
Hellooooo, this is a link:

Gooooo

为什么?

3 个答案:

答案 0 :(得分:3)

错字?

<a href=\"http://www.google.com\">Gooooo</a>

答案 1 :(得分:2)

您正在关闭链接:

<a href=\"http://www.google.com\"/>

需要删除跟踪/

答案 2 :(得分:1)

尝试单引用链接<a href='http://www.google.com'>Gooooo</a>