本文介绍了在Delphi中发送电子邮件,无需smtp,并在服务器上使用php函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Delphi,我想使用winsock发送一条短信给我的网络服务器,然后在服务器上使用一个电子邮件php功能来发布消息。

Using Delp i want to send a text message to my web server using winsock, and then use an email php function on the server to post the message.

首先我已经完成了发送过程(Procedure SendEmail):它读取文本文件(日志)并将其POST到我的服务器。在服务器上,该消息由名为email.php的电子邮件php函数接收(请参阅下面的功能内容):

First i have done the sending procedure (Procedure SendEmail): it reads a text file (log) and POST it to my server. On the server, the message is received by aa email php function named email.php (see content of that 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.

服务器上的email.php功能说明:

Description of 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 =/";
}
?>

(注意:我已经按照本指南的php邮件功能:)

(note:I have followed this guide for the php mail function: http://us3.php.net/manual/en/book.mail.php )

这里的一般想法是将消息发送到不使用smtp的服务器。但是,据我所见,看起来邮件被丢弃在我的服务器上。我对程序非常有信心,但不能确定php邮件功能。事情不容易调试。任何想法出了什么问题?或任何其他外观相似的解决方案?

The general idea here is to send the message to the server not using smtp. However, as far as i can see, it looks like the mail is dropped at my server. I'm pretty confident of the procedure, but not sure about the php mail function. The thing is not easy to debug. ANY idea what is going wrong? OR any other look alike solution?

任何帮助将不胜感激。谢谢。

Any help will be appreciated. Thanks.


我也在我的服务器站点询问有关使用smtp的支持。看起来我不能发送任何邮件(使用smtp),如果没有检查完成:

I have also ask support at my server site concerning use of smtp. Looks like i cannot send any mail (using smtp) if no check is done first:

We use pop-before-smtp mail authentication. You first need to

检查邮件,然后您可以发送
任何。您也不要在电子邮件客户端
设置中设置smtp
身份验证。一旦你检查了
邮件与POP身份验证不是
需要。

check the mail before you can send any. You also do not set smtp authentication in your e-mail client settings. Once you have checked the mail with POP authentication is not needed.

We use POP before SMTP authentication as it is a fairly

安全的方式来防止垃圾邮件发送者和
开放式继电器。不幸的是,这是
我们选择的配置。
对于希望发送邮件
列表的用户,我们有Mailman ValueApp,
,但是对于标准电子邮件,POP before
SMTP是如何设置服务器。

secure way to prevent spammers and open relays. Unfortunately, this is the configuration that we have chosen. For users who wish to send out mailing lists, we have the Mailman ValueApp, but for standard emailing, POP before SMTP is how the server is setup.


推荐答案

要测试您的PHP代码

你为什么不尝试写文件?
我将使用日期/时间和日志文件内容写入服务器上的文件,然后从

Why don't you try writing to a file?I would write to a file on the server with the date/time and the logfile contents, then access it from http://myserver.com/log.txt

关于Delphi部分:

我不会直接使用套接字,为什么不使用像Indy(TIDHTTP)这样的库。

I wouldn't use sockets directly, Why don't you use libraries like Indy (TIDHTTP).

使用它会很多

POST将像IdHttp1.Post(...)

The POST would be something like IdHttp1.Post(...)

这篇关于在Delphi中发送电子邮件,无需smtp,并在服务器上使用php函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 18:23