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

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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

4 Comments ,

4 Responses to “PEAR – MIME Mail”

  1. paul October 2, 2008 at 6:28 pm #

    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

  2. zak January 14, 2009 at 4:24 am #

    how did you record this did you put two micraphones on a person and record the sounds from each on seprat audio divices and then syncranis the two audio chanels or did you record with the same recording divice also what mic’s did you use and where dose the algorirthm come in

  3. zak January 14, 2009 at 1:40 pm #

    or is t that you used the algorithm to separate one row sound file into a file that sounds 3d and if this is the case then man you need to sell this info to a compainy for millions

  4. anil September 7, 2009 at 6:24 pm #

    hello i am enable to connect from pear i am working in php5 on xampp.. but i am not vonnected from pear library…

    please send me code and suggest that how to connect from pear

    thax..

    anil

Leave a Reply

More in php, php source code (81 of 111 articles)


What Actually happening in web world NOW !!! Please comment ...