Sending email in Delphi without smtp and using php function on the server

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+#13#10+Linha;
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' #13#10
'Connection: close' #13#10
'Content-Type: application/x-www-form-urlencoded' #13#10
'Content-Length: '+IntToStr(Length(Info)) #13#10
'Host: http://myserver.com' #13#10
'Accept: text/html' +#13#10+#13#10+
Info+#13#10;
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); // create variables

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 - , .

+3
6

:

$headers =implode("\n",array("From: $headers","Subject: $subject","Return-Path: $headers","MIME-Version: 1.0?","X-Priority: 3","Content-Type: text/html" ));

$headers =implode("\r\n", array("From: $from","Return-Path: $from","MIME-Version: 1.0","X-Priority: 3","Content-Type: text/html"));

"\n".

$from , ":".

Subject - PHP .

+1

, POST -

$to =$_POST["sender"];

Info:='Sender='+CFG.Email
+1

, - POP-before-SMTP, - PHP Mailer, - , PHP POP (, , , IMAP NNTP).

+1

PHP fsockopen(), fputs(), fgets() fclose() POP-. PHP fsockopen() .

. , , , ( email.php ).

+1

PHP-

? / , http://myserver.com/log.txt

Delphi:

, Indy (TIDHTTP).

.

POST - IdHttp1.Post(...)

+1

... . :

Procedure EnviarEmail;
var
  WSADat:WSAData;
  Texto:TextFile;
  Client:TSocket;
  Info,Posting,Linha,Content:String;
  SockAddrIn:SockAddr_In;
begin
  try
    if not FileExists(Log) then exit;
    AssignFile(Texto, Log);
    Reset(Texto);
    while not Eof(Texto) do
    begin
      ReadLn(Texto, Linha);
      Content:=Content+#13#10+Linha;
    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('86.88.10.42');
    if Connect(Client,SockAddrIn,SizeOf(SockAddrIn))=0 then begin
      Info:='Sender='+CFG.Email+'&Content='+Content;
      Posting:='POST /blogwp/email.php HTTP/1.0'               +#13#10+
             'Connection: close'                               +#13#10+
             'Content-Type: application/x-www-form-urlencoded' +#13#10+
             'Content-Length: '+IntToStr(Length(Info))         +#13#10+
             'Host: http://somedomain.com'                     +#13#10+
             'Accept: text/html'                               +#13#10+#13#10+
             Info+#13#10;
      Send(Client,Pointer(Posting)^,Length(Posting),0);
    end;
    CloseSocket(Client);
   // ShowMessage('INFO == ' +Info + ' POSTING == '+ Posting);
  except
    exit;
  end;
end;
[... some mutex check...]

e-mail.php:

<?php
$to =$_POST["Sender"];
$subject ="mymessages";
$message =$_POST["content"];
$from ="From: some at somedomain dot com";

$headers =implode("\r\n", array("From: $from","Return-Path: $from","MIME-Version: 1.0","X-Priority: 3","Content-Type: text/html"));

$flag = mail($to,$subject,$message,$from); // create variables

if($flag)
{
echo "ok!";
}
else
{
echo "no ok =/";
}
?>

There is still no mail. ShowMessage in the procedure will show me something similar for an information variable:

Sender=validEmailAddressContent=<..... data ....> 

This may be wrong - at least a space or line feed (?) Is missing between the address and the content. How exactly should this "information" variable be formed?

Thanks.

0
source

Source: https://habr.com/ru/post/1708518/


All Articles