<?php
/* Mail2SMTP 1.0
   ============= 
   The purpose of this script is to ease migration of existing web sites
   using the mail() functions to stop using the local MTA and use SMTP
   instead.
   
   All you need to do is replace each occurence of mail() with
   send_mail(), and - of couse - include this file.

   Please note that this function does not honor fancy options you may 
   have used as the fifth parameter to mail(). They are not a good idea
   anyways, as it makes your code MTA-dependant (more or less).

   Requires Mail and Net_SNMP pear packages.

   Configuration below:
   ====================  */

$smtp_server = "mail.net1.cc"; // use 'ssl://host.name.com' for ssl or just 'host.name.com' for plain SMTP
$smtp_port = 25; // default SMTP port is 25; for SSL - 465
$smtp_auth = false;
$smtp_username = "";
$smtp_password = "";

/* end of configuration */

function send_mail($to, $subject, $message, $additional_headers="", $optional_stuff="")
{
	require_once "Mail.php";
	global $smtp_server, $smtp_auth, $smtp_username, $smtp_password;
	$headers = array('To' => $to, 'Subject' => $subject);
	if ($additional_headers != "")
	{
		$additional_headers = explode("\r\n", $additional_headers);
		foreach ($additional_headers as $add_header)
		{
			$split_header = explode(":", trim($add_header));
			if ( count($split_header) == 2)
				$headers[$split_header[0]] = $split_header[1];
		}
	}
	$smtp = Mail::factory('smtp', array( 'host' => $smtp_server, 'auth' => $smtp_auth, 'username' => $smtp_username, 'password' => $smtp_password));
	$mail = $smtp->send($to, $headers, $message);
	return ( (PEAR::isError($mail)) ? 0 : 1 );
}

echo send_mail("info@net1.cc","Test", "Test message", "From: Ivan Ivanov <ivan@ivanov.com>\r\nCc: Bla Bla <bla@bla.com>\r\n");
?>
