Saturday, June 20, 2009

PHP Send Email Using PEAR

require_once "Mail.php";
$host = 'host name of smtp for local system localhost is used';
$recipients = 'email addresses of all to, cc & bcc recipients';
$headers = array ('From' => 'sender',
'To' => 'emails adresses for to field',
'Bcc' => '',
'Subject' => 'email subject',
'Reply-To' => '',
'MIME-Version' => '1.0',
'Content-Type' => 'text/html; charset=UTF-8',
'Content-Transfer-Encoding' => '8bit',
'X-Mailer' => 'PHP/'.phpversion()
);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => 25,
'auth' => FALSE ));
$mail = $smtp->send($recipients, $headers, $message);
if (PEAR::isError($mail)) {
return $mail->getMessage();
} else {
return true;
}

Friday, June 19, 2009

PHP Send Email Using SMTP

include("Mail.php");
/* mail set
up recipients, subject etc */
$recipients = "email addresses of all to, cc & bcc recipients";
$headers["From"] = "sender;
$headers["To"] = "emails adresses for to field";
$headers
["Subject"] = "ema
il subject";
$mailmsg = "Html body of mail";
/* SMTP server name, port, user/passwd */
$smtpinfo["host"] = "host name of smtp for local system localhost is used";
$smtpinfo["port"] = "25";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "smtpusername";
$smtpinfo["password"] = "smtpPassword";
/* Create the mail object using the Mail::factory method */
$mail_object =& Mail::factory("smtp", $smtpinfo);
/* Ok send mail */
$mail_object->send($recipients, $headers, $mailmsg);
?>