Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change report from send email to post to a php handler, need advice...
I created a Subversion commit mailer back in 2018 using FPC/Lazarus and Indy 10 and it has been working ok up until recently when it has had all kinds of problems due to email security updates on mail servers etc.

So I am trying to move away from sending the emails out from the subversion server to have it post to a php script on my webserver instead. Then the script can send the report emails to the recipients.

The existing application uses TIdSMTP to send the message, which is written into a TIdMessage property by a composing function reading data from the svn server.

Now I want to have a similar function but instead of using the SMTP mail transfer it should POST the data to a php script which should do the mailing from there. I have so far no problems sending emails from that server.

But it is on an ISP so I cannot run anything else but web-server stuff there. Hence the php script for mailing.

So how can I use Indy10 to simulate a form submit using the POST method to send the data the script will need?
This is what I need to send:

- Sender name and email as a single line string
- Recipients list in name/email pairs as a single line string
- Message body as an html encoded multi-line text

These are already created in the current application but stuffed into a TIdMessage container used by TIdSMTP.

I can create the website php script as a form handler and use it to send the needed data from an html form with the following items:
method POST
From, To : text type inputs
Message: textarea
Submit button

What I want to do is send the data from my application the same way as how the user clicking submit would do.

How can that be done?

Which Indy10 component to use and how do I set it up to perform the POST operation?
Simply use TIdHTTP.Post() with a TStringList as input containing name=value pairs.  That will send an HTTP request in the standard application/x-www-form-urlencoded format, just like a web browser would send for a basic HTML <form> element.

For example:

  PostData: TStringList;
  PostData := TStringList.Create;
    PostData.Add('From=' + ...);
    PostData.Add('To=' + ...);
    PostData.Add('Message=' + ...);
    IdHTTP1.Post(url, PostData);

And then on the PHP side, you can use $_POST to read in the values, eg $_POST['From'], etc.

Thanks, this looks promising!
Will try it ASAP tomorrow!

Quick question regarding the message body:
It is a multi-line HTML formatted text, can it be sent just like a simple variable as shown above?
(12-21-2023, 11:29 PM)BosseB Wrote: Quick question regarding the message body:
It is a multi-line HTML formatted text, can it be sent just like a simple variable as shown above?

Yes, simply add the entire HTML text including line breaks as a single string in the TStringList. The line breaks will be encoded accordingly when transmitted. Just like a browser would do with a multi-line <textarea> form element.

Just a final post on the actual end solution of my problem for future reference:

There is an additional command to use in order to make the problem I have go away.
It is described in this post on atozed.

Forum Jump:

Users browsing this thread: 1 Guest(s)