Page 1 of 1

help with .forward mails to mysql?

Posted: Sun Jan 12, 2003 3:30 pm
by JesperDK
Hi guys

I've been trying for hours to make a php script work, but I'm getting nowhere.

What I would like to do is having emails forwarded from a .forward file to a php script. The php script is then supposed to take the sender email, subject, body and headers and place into a mysql database.

I have set up the .forward file and as far as I can tell it's working: when I set it up with a php file that doesn't exist, the email is returned to me, but it doesn't do this now. However, nothing happens at all when I try to send an email. It's like it doesn't execute the script. I've tried to set it up to do something no matter what the email contains, but it doesn't help.

I am trying to use a slightly modified piece of code I found in this board:

Code: Select all

#!/usr/bin/php -q 
<?php 
//read in the message from the command line (sent to us by the pipe) 
$message = $argv&#1111;1]; 

//split the message by EOL to parse the header 
$messageList = split("\n",$message); 

//Database connection 
mysql_connect("localhost", "**user**", "**pass**");
$dd = mysql_select_db("**db**") 
or die("Could not select database"); 
$res = "INSERT INTO `test` ( `from` , `subject` , `headers` , `message` ) VALUES ('$mailheader&#1111;reply]', '$mailheader&#1111;subject]', 'c', 'd')";
echo $res;
$result = mysql_query($res)
   or die("Query failed2");
  
?>
Any help is really appreciated as I am out of ideas myself :)

Looking forward to hearing from you - and thank you,

Jesper

Posted: Sun Jan 12, 2003 6:15 pm
by gyardleydn
I haven't done this myself but I remember an article I saw. I put in some of the words I remember and but it in google and found this page.

Google search: "php mail forward"

Page: Incoming Mail and PHP

From site:

Code: Select all

$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
    $email .= fread($fd, 1024);
Seems you want to use this to read your piped input