Mail

An interface for sending EMails

Table of Contents
Mail (Previous) How to send a mail and the mailer backends (Next)
Last updated: Fri, 31 Oct 2014 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

Note by: mikech@livinginthepast-audioweb.co.uk
Since our PHP was updated to version 5.2.17 this package has stopped working.

'sendmail returned error code 127'

This comes from sendmail.php -

$result = pclose($mail);
if (version_compare(phpversion(), '4.2.3') == -1) {
// With older php versions, we need to shift the pclose
// result to get the exit code.
$result = $result >> 8 & 0xFF;
}

if ($result != 0) {
return PEAR::raiseError('sendmail returned error code ' . $result,
$result);
}

Note by: Adam
The way I fixed the not found error is by adding one line to the database script:

ini_set('include_path','.:/home/USER/php');

On the cPanel server I have sites hosted on each user has their own PHP directory where things like MDB2 are installed. You can make it easier, probably by adding this to it:

$includePath = ini_get('include_path');
ini_set('include_path',$includePath.':/home/USER/php');
Note by: bodemesh01@yahoo.com
Please make sure that your php.ini's include_path points to the PEAR directory.

Harlequine2 was right up there. The include_path on php.ini reads:
=============
; PHP's default setting for include_path is ".;/path/to/php/pear"
; http://php.net/include-path
include_path = ".;C:\xampp\php\PEAR"
======================

Change that to..

=============
; PHP's default setting for include_path is ".;/path/to/php/pear"
; http://php.net/include-path
include_path = ".;C:\xampp\php\PEAR\Mail"
=======================

by adding \Mail

That should solve the problem.
Note by: Baji Panchumarti
I am able to send inline images attachments using the basic Mail class by adding two header fields and formatting the msg body, see code below. I find it easier than using the Mail_Mime class.

<?php
require_once "Mail.php";

$_mailbox        =   Mail::factory('smtp', array(
  
'host'         => 'smtp.gmail.com',
  
'auth'         =>  FALSE,
  
'username'     => 'username@gmail.com',
  
'password'     => 'smtp_password',
  
'persist'      =>  FALSE  ));

$_boundary       =   sha1(date('r'));

$_headers        =   array(
  
'From'         => 'Baji <baji.panchumarti@gmail.com>',
  
'To'           => 'nobody@somebody.com',
  
'Subject'      => 'consuming too much pear',
  
'Content-Type' => 'multipart/related; boundary=DeS-mixed-{$_boundary}',
  
'MIME-Version' => '1.0'    );

$_inline_img     =   chunk_splitbase64_encodefile_get_contents(" path-to-image-file ")));

$_eml_body       =<<<HDS
--DeS-mixed-{$_boundary}
Content-Type: multipart/alternative; boundary="DeS-alt-
{$_boundary}"

--DeS-alt-
{$_boundary}
Content-Type: text/plain

This is what I look like after consuming pear

--DeS-alt-
{$_boundary}
Content-Type: multipart/related;
  boundary="DeS-related-
{$_boundary}"

--DeS-alt-
{$_boundary}
Content-Type: text/html

<b>This is what I look like after consuming pear</b>
<br><img src="cid:DeS-CID-
{$_boundary}" border=0 />

--DeS-related-
{$_boundary}
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-ID: <DeS-CID-
{$_boundary}>

{$_inline_img}
--DeS-related-
{$_boundary}--

--DeS-alt-
{$_boundary}--

--DeS-mixed-
{$_boundary}--
HDS;

$_to_eml  =  $_headers['To'];

$_mail    =  $_mailbox->send$_to_eml$_headers$_body );

if    (
PEAR::isError($_mail)) {

  echo 
date" Y-m-d H:i:s  ->  " ) . "email to {$_to_eml} failed, details : " $_mail->getMessage() . "\n\n";  }
else  {
  echo 
date" Y-m-d H:i:s  ->  " ) . "email sent to {$_to_eml} !\n\n";    }

?>

Note by: Reese
I was having the "not found" error too after installing Mail through cPanel.

What I think happened was the Mail directory and files were downloaded/installed but the main Mail.php file was not.

So what I did was download the manual installation archive on here. Inside the archive there's a Mail-1.2.0 folder and inside that folder there's Mail.php, a folder named Mail, and a folder named tests.
I went to my server's PHP include directory (/usr/lib/php), and put that main Mail.php file in there.

Then the proper way to include the class is require_once "Mail.php";
Note by: antichoc44@free.fr
Hello, I have the same message :

Fatal error: Class 'Mail' not found in /var/www/www-alpha/PEAR/Mail/mail.php on line 51

But my php.ini is correct (Include_path = /var/www/www-alpha/PEAR)

My PHP script correctly find mail.php but don't found the Class "Mail" that is extend ...

I don't find the déclaration of the Class "Mail" in the file install by PEAR ...

Excuse for my (so bad) english ...
Note by: harlequin2@gmx.de
@ cgoebels AT das-netz-erobern DOT de:

Please make sure that your php.ini's include_path points to the PEAR directory. If you installed PEAR through the console and had PEAR automatically add its path to php.ini, remember that the added include_path will be available after you have restarted your web server.
It's also important to check the correct case - even on Windows - so it should read require_once("mail.php") without a capital M.
Note by: cgoebels@das-netz-erobern.de
I get exactly the same error message, and I have made sure I've put require_once('Mail.php') and nothing else there. :(
Any ideas?
Is this a bug?
Note by: belldandy_sama_4@yahoo.com
here is the code:

89 $smtp = Mail::factory('smtp',
90 array ('host' => $host,
91 'auth' => true,
92 'username' => $username,
93 'password' => $password));
^-line number

here is the error:

Fatal error: Class 'Mail' not found in /home/intercon/public_html/addtemp.php on line 89

can anybody help me with this??

Note by: user@example.com
If you get an error like "Fatal error: Class 'Mail' not found" then you probably put

require_once "Mail/mail.php";

when you should have put

require_once "Mail.php";