View Single Post
  #4 (permalink)  
Old Feb 28th, 2007, 14:04
uchiha_obito uchiha_obito is offline
New Member
Join Date: Mar 2006
Age: 23
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP Forgot password script error

May be helpful to you.
Here is a function of sending the mails.It needs your own email account to open the smtp port.
Good luck!
PHP: Select all

<?php
function send_mail($to$subject 'No subject'$body) {
 
$loc_host "21cn_user";            //The sender name
 
$smtp_acc "username"//Smtp user name
 
$smtp_pass="password";          //Smtp user password
 
$smtp_host="smtp.XXX.com";    //SMTP server Address
 
$from="username@xxx.com";       //The receiver Email address
    
$headers "Content-Type: text/plain; charset=\"iso-8859-1\"\r\nContent-Transfer-
Encoding: base64"
;
    
$lb="\r\n";                    //linebreak
 
$hdr explode($lb,$headers);     //hdr
    
if($body) {$bdy preg_replace("/^\./","..",explode($lb,$body));}//Body
 
$smtp = array(
  
//1、EHLO,back 220 or 250
  
array("EHLO ".$loc_host.$lb,"220,250","HELO error: "),
  
//2、Send Auth Login,back 334
  
array("AUTH LOGIN".$lb,"334","AUTH error:"),
  
//3、Send the username incoded by Base64,back 334
  
array(base64_encode($smtp_acc).$lb,"334","AUTHENTIFICATION error : "),
  
//4、Send the Password incoded by Base64,back 235
  
array(base64_encode($smtp_pass).$lb,"235","AUTHENTIFICATION error : "));
 
//5、Send Mail From,back 250
 
$smtp[] = array("MAIL FROM: <".$from.">".$lb,"250","MAIL FROM error: ");
 
//6、Send Rcpt To。back250
 
$smtp[] = array("RCPT TO: <".$to.">".$lb,"250","RCPT TO error: ");
 
//7、send DATA,back 354
 
$smtp[] = array("DATA".$lb,"354","DATA error: ");
 
//8.0、send From
 
$smtp[] = array("From: ".$from.$lb,"","");
 
//8.2、send To
 
$smtp[] = array("To: ".$to.$lb,"","");
 
//8.1、Send title
 
$smtp[] = array("Subject: ".$subject.$lb,"","");
 
//8.3、Send Header
 
foreach($hdr as $h) {$smtp[] = array($h.$lb,"","");}
 
//8.4、Send blank row,end send Header
 
$smtp[] = array($lb,"","");
 
//8.5、send the main body
 
if($bdy) {foreach($bdy as $b) {$smtp[] = array(base64_encode
($b.$lb).$lb,"","");}}
 
//9、Send “.” indicates the end of the body,back 250
 
$smtp[] = array(".".$lb,"250","DATA(end)error: ");
 
//10、send Quit,exit,back 221
 
$smtp[] = array("QUIT".$lb,"221","QUIT error: ");
 
//Open the smtp server port
 
$fp = @fsockopen($smtp_host25);
 if (!
$fp) echo "<b>Error:</b> Cannot conect to ".$smtp_host."<br>";
 while(
$result = @fgets($fp1024)){if(substr($result,3,1) == " ") { break; }}
 
$result_str="";
 
//Send the commands/datas in smtp arrays
 
foreach($smtp as $req){
  
//Send messages
  
@fputs($fp$req[0]);
  
//if needs the message returned by servers,then:
  
if($req[1]){
   
//receive the messages
   
while($result = @fgets($fp1024)){
    if(
substr($result,3,1) == " ") { break; }
   };
   if (!
strstr($req[1],substr($result,0,3))){
    
$result_str.=$req[2].$result."<br>";
   }
  }
 }
 
//close the link
 
@fclose($fp);
 return 
$result_str;
}
?>
Reply With Quote