Feb 1 2008

PEAR - MIME Mail

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

TAGS: ,

1 Comments on this post

Trackbacks

  1. 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
    - Paul

    October 2nd, 2008 at 6:28 pm

LEAVE A COMMENT

Subscribe Form

Subscribe to Blog

Sponsors

    Advt on sajithmr.com
    Advt on sajithmr.com
    Advt on sajithmr.com
    Itslife Online

Recent Comments

  • sexasion: Best of the Best sexypicturess.blogspot.com
  • memo ezzo: live sex hot video
  • muhammadashraf44: i am ashraf from karachi i have only one girl in sex and one night plzz
  • Arun Basil Lal: Dude, The comments to this post are ever flowing in, I am gonna post some hot pics on my blog too.....
  • badar: plz send me the hot pic

Recent Readers

JOIN MY COMMUNITY!

Recent Posts