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
|
|
|
|
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

