Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Delphi中不使用smtp发送电子邮件,并在服务器上使用php函数_Php_Delphi_Email - Fatal编程技术网

在Delphi中不使用smtp发送电子邮件,并在服务器上使用php函数

在Delphi中不使用smtp发送电子邮件,并在服务器上使用php函数,php,delphi,email,Php,Delphi,Email,使用Delphi,我想使用winsock向我的web服务器发送一条文本消息,然后在服务器上使用电子邮件php函数发布消息 首先,我完成了发送过程(过程SendEmail):它读取一个文本文件(日志)并将其发布到我的服务器。在服务器上,消息由一个名为email.php的电子邮件php函数接收(请参见下面该函数的内容): 服务器上email.php函数的说明: <?php $to =$_POST["sender"]; $subject ="mymessages"; $message =$_PO

使用Delphi,我想使用winsock向我的web服务器发送一条文本消息,然后在服务器上使用电子邮件php函数发布消息

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

服务器上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 =/";
}
?>
在发送之前先检查邮件 任何您也不设置smtp 电子邮件客户端中的身份验证 设置。一旦你检查了 不支持使用POP身份验证的邮件 需要

We use POP before SMTP authentication as it is a fairly
防止垃圾邮件发送者和 打开继电器。不幸的是,这是错误的 我们选择的配置。 对于希望发送邮件的用户 列表,我们有Mailman ValueApp, 但对于标准电子邮件,请在发送前弹出 SMTP是服务器的设置方式


下面的行是错误的:

$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应仅为电子邮件地址,不包括“from:”


不需要设置主题标题-PHP会为您这样做。

您需要确保POST值名称的大小写匹配-您有

$to =$_POST["sender"];


好的,谢谢。。。我已申请更正。现在我确切地说:

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...]
服务器上的email.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 =/";
}
?>

还是没有收到邮件。过程中的ShowMessage为info变量显示如下内容:

Sender=validEmailAddressContent=<..... data ....> 
Sender=validEmailAddressContent=
这可能是错误的-地址和内容之间至少缺少空格或换行符(?)。这个“info”变量的格式应该是怎样的


谢谢

既然您注意到ISP需要在SMTP之前通过POP进行身份验证,那么您应该考虑使用类似的方法来促进这种交互,或者使用PHP函数(恰好与IMAP和NNTP的函数完全相同)。

在PHP端,您可以使用fsockopen()、fputs()、fgets(),和fclose()来处理与POP服务器的连接需要。fsockopen()的PHP帮助应该为您提供所需的详细信息


旁注:可能不是问题,但您需要确保您没有创建开放中继的混合(允许其他人使用您的email.php端点代表您发送电子邮件)。

测试您的php代码

你为什么不试着写一个文件呢? 我会将日期/时间和日志文件内容写入服务器上的一个文件,然后从

至于德尔福部分:

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

使用它会简单得多


帖子类似于IdHttp1.POST(…)

为什么不在服务器中使用web服务呢?web服务将收集消息数据并发送消息。它更简单,不面向套接字。请评论你的帖子,而不是“回答”它们。我已经设法用PEAR和以下脚本发送邮件:谢谢-我将查看PHO Mailer。否则,什么才是正确的pop电子邮件检查器?POP:从php.net/imap-open,您可以看到第二个示例:$mbox=imap_open(“{localhost:110/pop3}收件箱”,“用户id”,“密码”);非常感谢。我会试试的。谢谢,我会看看并试试fsockopen()
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...]
<?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 =/";
}
?>
Sender=validEmailAddressContent=<..... data ....>