PHP fopen incoming email .txt attachment

420 Views Asked by At

What I'd like to do is send an email or text from a phone to an email address that forwards/pipes the email to a PHP script. The to, from, subject and body of the message is parsed and is compared to an SQL database where the body of the email is compared to previous entries and addition information is sent back to the original sender. The code starts like this...

#!/usr/bin/php -q
<?php 
//Listen to incoming e-mails
$sock = fopen ("php://stdin", 'r');

$email = '';
//Read e-mail into buffer
while (!feof($sock))
{
    $email .= fread($sock, 1024);
}

//Close socket
fclose($sock);

This script works fine for regular email to email correspondence. However when a text message is executed the content/body of the email is within a .txt attachment. I have no clue what to put for the filename in order to open the .txt file using the fopen command. The .txt attachment is always "slide1.txt" I've tried fopen("slide1.txt", "r"); fopen("/slide1.txt", "r"); fopen("php://stdin/slide1.txt", 'r'); and a few others with no luck. Nothing is returned.

Any ideas?

0

There are 0 best solutions below