Search code examples
phpemailpearmime

Error message on sending test message with PEAR mail


I have installed the latest versions of PEAR Mail and Mail_Mime and I'm trying to send a test message, using the following test email from this page, i.e.

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

        // Constructing the email
        $sender = "**** <info@****.com>";                              // Your name and email address
        $recipient = "**** <****@gmail.com>";                           // 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
        $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);
?>

And the message is not getting sent. Checking my error log turned up:

[24-Jul-2012 02:14:50] PHP Fatal error: Call to undefined method Mail_mimePart::encodeHeader() in /home/**/php/Mail/mime.php on line 1330

I wonder if anyone knows what this error message relates to and what can be done about it? Line 1330 in mime.php is the 4th line in this function:

function encodeHeader($name, $value, $charset, $encoding)
    {
        $mime_part = new Mail_mimePart;
        return $mime_part->encodeHeader(
            $name, $value, $charset, $encoding, $this->_build_params['eol']
        );
    }

Solution

  • include_once("Mail/mime.php");
    

    Should be your include.