2011-06-14 121 views
0

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

所以我写了这个代码:

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

$email = "[email protected]"; 
$from_addr = "example <[email protected]>"; 
$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

错字?

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

哈哈你对:) – xRobot 2011-06-14 09:23:17

1

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

2

您关闭链接:

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

尾随/需要被移除。