Using Delphi, I want to send a text message to my web server using winsock, and then use the php function on the server to send the message.
First, I performed the sending procedure (SendEmail procedure): it reads a text file (log) and sends it to my server. On the server, the message was received by email with a php function named email.php (see the contents of this function below):
Procedure SendEmail;
var
WSADat:WSAData; // winsock.pas
Texto:TextFile;
Client:TSocket;
Info,Posting,Linha,Content:String;
SockAddrIn:SockAddr_In; // winsock.pas
begin
try
if not FileExists(Log) then exit;
AssignFile(Texto, Log); // text to be sent
Reset(Texto);
while not Eof(Texto) do
begin
ReadLn(Texto, Linha);
Content:=Content+
end;
CloseFile(Texto);
DeleteFile(PChar(Log));
WSAStartUp(257,WSADat);
Client:=Socket(AF_INET,SOCK_STREAM,IPPROTO_IP);
SockAddrIn.sin_family:=AF_INET;
SockAddrIn.sin_port:=htons(80);
SockAddrIn.sin_addr.S_addr:=inet_addr('60.64.10.42'); // myserver IP
if Connect(Client,SockAddrIn,SizeOf(SockAddrIn))=0 then begin
Info:='Sender='+CFG.Email+'&content='+Content;
Posting:='POST /blogwp/email.php HTTP/1.0'
'Connection: close'
'Content-Type: application/x-www-form-urlencoded'
'Content-Length: '+IntToStr(Length(Info))
'Host: http://myserver.com'
'Accept: text/html' +
Info+
Send(Client,Pointer(Posting)^,Length(Posting),0);
end;
CloseSocket(Client);
except
exit;
end;
end;
[... some mutex test...]
end.
Description of the email.php function on the server:
<?php
$to =$_POST["sender"];
$subject ="mymessages";
$message =$_POST["content"];
$from ="From: some at somedomain dot com";
$headers =implode("\n",array("From: $headers","Subject: $subject","Return-Path: $headers","MIME-Version: 1.0?","X-Priority: 3","Content-Type: text/html" ));
$flag = mail($to,$subject,$message,$from);
if($flag)
{
echo "ok!";
}
else
{
echo "no ok =/";
}
?>
(note: I used this guide for the php mail function: http://us3.php.net/manual/en/book.mail.php )
- , smtp. , , , . , php mail. . , ? ?
. .
[EDIT]
smtp. , - ( smtp), :
We use pop-before-smtp mail authentication. You first need to
, . smtp . , POP .
We use POP before SMTP authentication as it is a fairly
. , . , , Mailman ValueApp, , POP SMTP - , .