gpt4 book ai didi

php - 在没有smtp的情况下在Delphi中发送电子邮件并在服务器上使用php函数

转载 作者:可可西里 更新时间:2023-11-01 00:53:56 29 4
gpt4 key购买 nike

使用 Delphi,我想使用 winsock 将文本消息发送到我的 Web 服务器,然后使用服务器上的电子邮件 php 功能来发布消息。

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

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函数说明:

<?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 邮件功能的指南:http://us3.php.net/manual/en/book.mail.php)

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

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

[编辑]我还在我的服务器站点上询问有关使用 smtp 的支持。如果不首先进行检查,我似乎无法发送任何邮件(使用 smtp):

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

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

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.

最佳答案

下面一行是错误的:

$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 应该只是电子邮件地址,不包括“发件人:”。

无需设置主题 header - PHP 会为您完成。

关于php - 在没有smtp的情况下在Delphi中发送电子邮件并在服务器上使用php函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/874965/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com