Sakura Sakura - 1 year ago 57
PHP Question

how to send html mails using PEAR mail

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.

mail body looks like this:

$body = <<<EOD

Hiya $username

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

Latest Haves
<a href="">Titan Fast Track SunGlass</a>


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

Answer Source

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


        // Constructing the email
        $sender = "Leigh <>";                              // Your name and email address
        $recipient = "Leigh <>";                           // 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>This is a html message</p></body></html>';  // HTML version of the email
        $crlf = "\n";
        $headers = array(
                        'From'          => $sender,
                        'Return-Path'   => $sender,
                        'Subject'       => $subject

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

        // Setting the body of the email

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

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

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