Email using PHP script

Hey. I want to forward all emails (that get to my inbox) to a php script and upload the contents of the email and save it in a file. So do it, I correctly added the mail forwarding with the channel.

Forwarding address: tickets@ana.stage.centuryware.org

Trumpet to the program: /home/centuryw/public_html/stage/ana/osticket/upload/api/pipe.php

I used the following script as pipe.php

#!/usr/bin/php –q <? /* Read the message from STDIN */ $fd = fopen("php://stdin", "r"); $email = ""; // This will be the variable holding the data. while (!feof($fd)) { $email .= fread($fd, 1024); } fclose($fd); /* Saves the data into a file */ $fdw = fopen("mail.txt", "w+"); fwrite($fdw, $email); fclose($fdw); /* Script End */ 

But there was no output file, and all the emails again ended up in my inbox. Can anybody help me?

+7
source share
5 answers

Make sure the execution bit is set in the PHP file (i.e. chmod +x pipe.php ).

+4
source

try the following two options:

  • Firstly, your php file must have permission to execute (from the group of owners, at least), otherwise it will not work.

  • What did you use when using a forwarder? You must also specify the php compiler path in beginnig.

I recently wrote an article about the full detailed pipeline process for php programs , you might like to watch. Let me know if you have another question. Thanks.

+3
source

I know this question is 2 years old, but hopefully this will help anyone who stumbles upon it like me.

I had exactly the same problem, and I spent years logging errors, etc. Then I noticed that my script (and this one) had short short PHP tags (i.e. <? ), And my PHP configuration file was off. I changed the tag to <?php and the script works! Obvious but easy to miss ...

+3
source

Chanaka -

This does not apply to why there is no output file, but ...

Don't you want to use a+ in your fopen() call? The w+ argument will remove any content that already exists in your output file.

PS: Have you tried to do a simple test that writes to the output file using dummy text (rather than input from an email message) as the content?

Jeff Cohan

0
source

If this is really an email field, why not use IMAP (PHP) ? There are many classes for reading mail using imap @ phpclasses.org

-1
source

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


All Articles