ارسال المعلومات الى البريد الالكتروني المحدد من برنامج دلفي
#6
من الارشيف :p
لا تحتاج استضافة مدفوعة

class.php
PHP كود :
<?php
class SMTPClient
{
function 
SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body)

{
$this->SmtpServer = $SmtpServer;
$this->SmtpUser = base64_encode ($SmtpUser);
$this->SmtpPass = base64_encode ($SmtpPass);
$this->from = $from;
$this->to = $to;
$this->subject = $subject;
$this->body = $body;
    if (
$SmtpPort == "") 
    {
    
$this->PortSMTP = 25;
        }else{
    
$this->PortSMTP = $SmtpPort;
    }
}
function 
SendMail ()
{
    if (
$SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP)) 
    {
            
fputs ($SMTPIN, "EHLO ".getenv('MyHost')."\r\n");  
            
$talk["hello"] = fgets ( $SMTPIN, 1024 ); 
            
fputs($SMTPIN, "auth login\r\n");
            
$talk["res"]=fgets($SMTPIN,1024);
            
fputs($SMTPIN, $this->SmtpUser."\r\n");
            
$talk["user"]=fgets($SMTPIN,1024);
            
fputs($SMTPIN, $this->SmtpPass."\r\n");
            
$talk["pass"]=fgets($SMTPIN,256);
            
fputs ($SMTPIN, "MAIL FROM: <".$this->from.">\r\n");  
            
$talk["From"] = fgets ( $SMTPIN, 1024 );  
            
fputs ($SMTPIN, "RCPT TO: <".$this->to.">\r\n");  
            
$talk["To"] = fgets ($SMTPIN, 1024); 
            
fputs($SMTPIN, "DATA\r\n");
            
$talk["data"]=fgets( $SMTPIN,1024 );
            
fputs($SMTPIN, "To: <".$this->to.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n\r\n\r\n".$this->body."\r\n.\r\n");
            
$talk["send"]=fgets($SMTPIN,256);
           
//CLOSE CONNECTION AND EXIT ... 
           
fputs ($SMTPIN, "QUIT\r\n");  
           
fclose($SMTPIN); 
    }  
return 
$talk;
}         
}
?>
config.php
PHP كود :
<?php
//Server Address
$SmtpServer="mail . rambler . ru";
$SmtpPort="587";
$SmtpUser="user";
$SmtpPass="pass";
?>
api.php
PHP كود :
<?php
include('config.php');
include(
'class.php');
if(
$_SERVER["REQUEST_METHOD"] == "POST")
{
$to = $_POST['to'];
$from = $_POST['from'];
$subject = $_POST['sub'];
$body = $_POST['message'];
$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
$SMTPChat = $SMTPMail->SendMail();
echo 
'Send mail '.$SMTPChat["data"];
}
?>
الدلفي
PHP كود :
procedure TForm2.Button1Click(Sender: TObject);
var 
paramstr:TStringList;
begin
 paramstr
:=TStringList.Create;
try
paramstr.Add('to=any @ any . com');
paramstr.Add('from=user @ rambler .ru');
paramstr.Add('sub=مرحبا');
paramstr.Add('message=hello world');
ShowMessage(IdHTTP1.Post('http://site.com/smtpmail/api.php',paramstr) );

finally
 
paramstr.Free;
end;
end; 
النتيجة
[صورة: kgV0iW.png]
الرد


الردود في هذا الموضوع
ارسال المعلومات الى البريد الالكتروني المحدد من برنامج دلفي - بواسطة onexite - 25-11-2014, 08:31 PM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم