PEAR - MIME Mail
- 1 Comment

When you send mail from php code, you use mail() function for this purpose. Here is another library from PEAR for sending MIME mails including html mails, attachments, inline picture attachment , plain text mail etc.
The steps to install this library is :
pear install http://download.pear.php.net/package/Mail_Mime-1.5.2.tgz
pear install Mail
(you need a pre-installed PEAR library)
From the php code you can create a function for sending mails
public function sendMail($Content,$to,$subject,$from=’no-reply@mysite.com’, $type=’html’,$attachment=false )
{
require_once (”Mail.php”);
require_once (”Mail/mime.php”);
$crlf = “\n”;
$hdrs = array(
‘From’ => $from,
‘Subject’ => $subject
);
$mime = new Mail_mime($crlf);
if($type== ‘html’)
$mime->setHTMLBody($Content); // html content
else
$mime->setTXTBody($Content); // test content
//you can pass $attachment as array of file paths
if($attachment)
foreach($attachment as $file)
$mime->addAttachment($file, ‘image/jpeg’);
//do not ever try to call these lines in reverse order
$body = $mime->get();
$hdrs = $mime->headers($hdrs);
$mail =& Mail::factory(’mail’);
$mail->send($to, $hdrs, $body);
}
You can use this link for another example: http://pear.php.net/manual/en/package.mail.mail-mime.example.php
For more examples go : http://pear.php.net/manual/en/package.mail.mail-mime.php
1 Comments on this post
Trackbacks
-
paul said:
Hey Tahnks for your information…
My problem with mime is that maybe I installed it the wrong directory. You mention that we need a pre-installed PEAR library. I installed this in my ‘File Manager’ section under Yahoo Web hosting. So, when I go to install mime, I get the follwing error:
ERROR: Adding package pear.php.net/Mail_Mime to registry failed
ERROR: Adding package pear.php.net/Mail_mimeDecode to registry failed
What am I doing wrong?
Thanks
- PaulOctober 2nd, 2008 at 6:28 pm




