postimg
Apr 2009 15

Send An HTML & Plain Text Email Using An SMTP Server With PHP & PEAR0

Posted In PHP By Tony Virelli

You have to have PEAR installed. You can get more information at http://pear.php.net.

<?php
include('Mail.php');
include('Mail/mime.php');
 
$text = 'Hello,\nHow are you doing?';
$html = 'Hello,
How are you doing?';
 
$smtpinfo["host"] = "smtp.domain.com";
$smtpinfo["port"] = "25";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "SMTP USERNAME";
$smtpinfo["password"] = "SMTP PASSWORD";
 
$recipients = "recipient@domain.com";
$headers["From"] = "From Name ";
$headers["To"] = "recipient@domain.com";
$headers["Subject"] = "Email Subject";
 
$mime = new Mail_mime();
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
 
$body = $mime->get();
$headers = $mime->headers($headers);
 
$mail =& Mail::factory('smtp', $smtpinfo);
$mail->send($recipients, $headers, $body);
 
if(PEAR::isError($mail)){
echo("
 
There was an error: " . $mail->getMessage() . "
 
");
}else {
echo("
 
Message Sent To $to
 
");
}
?>
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • email
  • LinkedIn
  • MySpace
  • PDF
  • Reddit
  • RSS
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter

Leave a comment

Get Adobe Flash playerPlugin by wpburn.com wordpress themes