Hi,
I am wondering if someone would be able to help me, I am having a big issue finding information and an example, of a PHP pipe email to MYSQL,
I have made the email web interface, and all MYSQL tables etc, but I can't figure out who to pipe all emails to a PHP script.
I would also like to know how would I allow users IMAP of their email account?
Thanks
Russell H.


This is what I came up with
This is what I came up with just to test if I successfully sent the message to the pipe script
#!/usr/bin/php -q
<?php
// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
$outFile = fopen("/home/****/public_html/bmail/script/emailResult.txt","w");
fwrite($outFile,$email);
fclose($outFile);
?>
While this script works, for some reason it send an error message back to the sender
If you would like to try and see the error send email to {link saved}
Hi Russell, Can you copy /
Hi Russell,
Can you copy / paste the body of the error message into a reply to this thread, that would help...
Thanks,
David.
This message was created
This message was created automatically by mail delivery software.
A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:
pipe to |/home/bonush/public_html/bmail/script/collect2mysql.php
generated by {email saved}
The following text was generated during the delivery attempt:
------ pipe to |/home/bonush/public_html/bmail/script/collect2mysql.php
generated by {email saved} ------
X-Powered-By: PHP/5.2.11
Content-type: text/html
{content saved}
Hi Russell, Ignoring the
Hi Russell,
Ignoring the error message for a moment, have you proven whether the PHP script is actually being called on receipt of an appropriate email.
The quickest way would be to make it output some debug data to a log file so that you can see what's happened.
Create a folder in the same directory as collect2mysql.php called "logs". Then, add this code to the top of collect2mysql.php:
$log = fopen("logs/log.txt");fwrite($log,"TEST");
fclose($log);
Send your email; then check for "log.txt" in the /logs/ folder. Delete it before each test; or make a note of the timestampe when you do ls -l, it should update every time if it's being called...
Cheers,
David.
PHP script is fine, it was a
PHP script is fine, it was a server error from what the server guys said.
Now I guess I gotta start coding the hardcore code!
Yeah that's what we like :)
Hey David wondering can you
Hey David wondering can you see an error with this code below? all I am doing is a test to see if it will insert the message into the DB... which it is not...
// Send email to database.mysql_query("INSERT INTO tbl_bmail_messages (headers, to, from, subject, message)
VALUES ('".$headers."', '".$to."', '".$from."', '".$subject."', '".$message."')");
Hi Russell, Normally, you
Hi Russell,
Normally, you would use mysql_error() to display the result of the query (assuming that it gets that far); but of course in this scenario it is the mail deamon that is running the script; so instead; what you need to do is log the error message to a file instead.
Create a folder in the same directory as your script called "log", and make sure that it is writable by all users (mode 777 - easiest way is to right-click on the folder in the remote window in your FTP program, and look for Permissions, or maybe Properties and then Permissions, and make sure that they folder is writeable by all users - Owner / Group / World).
Then, in your script, use:
// Send email to database.mysql_query("INSERT INTO tbl_bmail_messages (headers, to, from, subject, message)
VALUES ('".$headers."', '".$to."', '".$from."', '".$subject."', '".$message."')");
$error = mysql_error();
if ($error)
{
$fp = fopen("log/error.txt","w");
fwrite($fp,$error);
fclose($fp);
}
Then do what is necessary to make your script run; and study for log/error.txt for any MySQL error information that may indicate the problem.
If no file is created; you can use the same technique higher up your script to output other debug information; such as a simple "here" message to make sure that your script is behaving as you expect up to a control point.
Hope this helps!
Cheers,
David.