The latest problem is a script that takes incoming emails to a certain address and puts them in the database. I included the script below called 'Gateway.php'.
This worked great on my local machine with the settings in the /etc/aliase also included below.
But now that the host has me using the procamil.rc (also included)
I get the subject line in the body.
The only good thing so far from all of this is that I think I an use procmail to my advantage to strip the To: From: Subject: and Body: of the email and leave the rest(attachments etc) for /dev/null.
This would help alot since Outlook Exp. has some extra header info in the email.
So below are the scripts, any help would be appreciated.
Again all of this works perfect on my machine but they are not allowing me the use of the aliase file for sendmail. Though using procmail to strip the above info my be better in the long run?
Thanks,
--Al
////////////Gateway.php////////////
#!/usr/local/bin/php -q
<?php
/* $Id: gateway.php,v 1.11 2002/10/28 15:52:27 root Exp $
* Copyright (C) 2002 Justin Mazzi <[EMAIL PROTECTED]>
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Dont forget to come by linuxgroup.net ;-)
*/
/* Setup some vars */ $stdin = fopen("php://stdin", "r");
/* Fill the values in with your info */ $sqlhost = "localhost"; $sqluser = ""; $sqlpass = ""; $sqldb = "";
/* This is used for bounced emails. */ $support_email = "[EMAIL PROTECTED]"; $support_name = "Al Nutile";
/* make the mysql connection */ mysql_connect($sqlhost, $sqluser, $sqlpass); mysql_select_db($sqldb);
/* read in the pipe from stdin */ while (!feof($stdin)) { $buffer = fgets($stdin, 4096); $message[] .= $buffer; }
/* Get the email headers */ foreach($message as $header_build) {
if (preg_match("/^$/", $header_build)) break; $header_build = preg_replace("/:\s/", ":", $header_build); if (preg_match("/:/", $header_build)) { $vars = preg_split("/:/", $header_build, 2); if ($vars[1]) { chop($header[$vars[0]] = $vars[1]); } } }
/* Error out if there's an attachment */
if (preg_grep("/oundary=/", array_values($message))) {
$attachment = 1;
$email_body = "Hi,\n\tSorry, your message contained one or more attatchments. ";
$email_body .= "Our email system does not currently accept ";
$email_body .= "attachments. Please attempt to resend the email ";
$email_body .= "without an attachment.\n\n -$support_name\n";
$email_body .= "$support_email";
$subject = "Re:$header[Subject]";
$from = "From:<$support_name>$support_email";
$to = $header['From'];
mail($to, "$subject", "$email_body", $from);
//exit("Message had an attachment");
}
/* strip out Re:'s in subject */
if ($header['Subject']) {
$header['Subject'] = preg_replace("/\s*Re:\s*/", "", $header['Subject']);
}
/* initialize To: header */
$string = $header['To'];
$separat = "@";
$to = substr($string, 0, strlen($string)-strlen (strstr ($string,$separat)));
$sql = "select sport_id from sports where email = '$to'";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$sport_id = "{$row["sport_id"]}";
}
/* Turn from into an ID */
$from = $header['From'];
$string = preg_match("/</", "/$from/", $string);
if (!$string)
{
$from = $from;
} else {
$from = substr(strrchr($from, "<"), 1);
$from = str_replace(">", "", "$from");
}
$query = "select reporter_id from reporters_info where email = '$from'";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
if ($num_rows == '0')
{
mail("$from", "NEPSO || Reporters..",
"
Sorry there was no matching username for the email sent.
Please make sure the From address on the email is
the same email address you used to register with.",
"From:Support Nepso<[EMAIL PROTECTED]>");
exit;
} else {
while ($row = mysql_fetch_array($result))
{
$reporter_id = "{$row["reporter_id"]}";
}
}
/* fix empty subject header */ $header['Subject']=preg_replace("/\n/","",$header['Subject']); if ($header['Subject']=="") { $header['Subject'] = "{no subject}"; }
/* Get the message body */ for($i = count($header) + 1; $i <= count($message); $i++) { $body .= $message[$i]; } if (preg_match("/^\n$/",$body)) { $body = "[empty message body]"; } else { $body = mysql_escape_string($body); } if ($attachment>0) { $body="[message contained one or more attachments]"; }
$subject = mysql_escape_string($header['Subject']);
$query = "insert into reports (author, sport_id, subject, body, date, time) ";
$query .= "values ('$reporter_id', '$sport_id', '$subject', '$body', now(), now())";
mysql_query($query);
?>
////////end gateway.php////////////
/////procmail file/////////
:0 * $RECIP ?? [EMAIL PROTECTED] { :0rf | /home/nepso/nepso-mail/report_gateway.php
:0 /dev/null
}
/////////////end procmail file///////
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php