Location: PHPKode > projects > MyTodos > sendmail.php
<?
###################################################
#Copyright (C) 2002 Lihua Gao (hide@address.com) 
#
#$Id: sendmail.php,v 1.1 2002/12/05 10:03:33 gaolihua Exp $
#
#This file is part of myTodos.
#
#myTodos is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#myTodos is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with myTodos; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#####################################################
?>
<?

// parameter, must be initiated for a perticular mail server
$server="p90linux";
$port_smtp="25";


// send a mail
// return 0 if error otherwise returnn 1
function sendmail($subject, $data, $mailto, $mailfrom) 
{ 
   global $SMTP_GLOBAL_STATUS; 
   global $server; 
   global $port_smtp; 

   $smtp = fsockopen($server, $port_smtp);
   if ($smtp == 0){
	   //echo "can't connect to smtp server\n";
	   return 0;
   }
   $text = fgets($smtp, 1024);
   //echo "connect to smtp:".$text."\n";

   fputs($smtp, "MAIL FROM: <$mailfrom>\r\n");
   $text = fgets($smtp, 1024);
   //echo "mail from:".$text."\n";

   fputs($smtp, "RCPT TO: <$mailto>\r\n");
   $text = fgets($smtp, 1024);
   //echo "rcpt to:".$text."\n";


   fputs($smtp, "DATA\r\n"); 
   $line = fgets($smtp, 1024); 
   $SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] = substr($line, 0, 1); 
   $SMTP_GLOBAL_STATUS[$smtp]["LASTRESULTTXT"] = substr($line, 0, 1024); 

   if ($SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] <> "3") return 0; 

	fputs($smtp, "Mime-Version: 1.0\r\n"); 
	fputs($smtp, "Subject: $subject\r\n");     
	fputs($smtp, "$data\r\n\r\n"); 
	fputs($smtp, ".\r\n"); 
      $line = fgets($smtp, 1024); 
	if (substr($line, 0, 1) <> "2") { return 0; }


   // logging
   $logfile = fopen("sendmail.log","a");
   fputs($logfile, "=== mail to: ".$mailto."/".date("d.M.Y h:m:s A", time())." \n");
   fputs($logfile, "subject: ".$subject."\n");
   fputs($logfile, "details: ".$data."\n");
   fclose($logfile);


   return 1; 
};
  

?>
Return current item: MyTodos