dsnyder Posted July 19, 2010 Share Posted July 19, 2010 I Have an email piping script that works fine, BUT there are a couple things I need it to do that I have thus far not been able to accomplish. Any Help would be GREATLY appreciated. As I said the code works fine.. when an email is sent to the email address as [email protected] it is piped to my script and saved to mysql database, the problem is how it is saved, and I need to do a if statement whereas if the subject contains [string of numbers] Here is the code: #!/usr/bin/php -q <?php require('config.php'); $notify= '[email protected]'; // an email address required in case of errors $todaysdate = date("m\/j\/Y"); $thetime = date("g:i a"); // read from stdin $fd = fopen("php://stdin", "r"); $email = ""; while (!feof($fd)) { $email .= fread($fd, 1024); } fclose($fd); // handle email $lines = explode("\n", $email); // empty vars $from = ""; $subject = ""; $headers = ""; $message = ""; $splittingheaders = true; for ($i=0; $i < count($lines); $i++) { if ($splittingheaders) { // this is a header $headers .= $lines[$i]."\n"; // look out for special headers if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) { $subject = $matches[1]; } if (preg_match("/^From: (.*)/", $lines[$i], $matches)) { $from = $matches[1]; } if (preg_match("/^To: (.*)/", $lines[$i], $matches)) { $to = $matches[1]; } } else { // not a header, but message $message .= $lines[$i]."\n"; } if (trim($lines[$i])=="") { // empty line, header section has ended $splittingheaders = false; } } if ($conn = @mysql_connect($dbhost,$dbuser,$dbpass)) { if(!@mysql_select_db($dbname,$conn)) mail($email,'Email Logger Error',"There was an error selecting the email logger database.\n\n".mysql_error()); $from = mysql_real_escape_string($from); $to = mysql_real_escape_string($to); $subject = mysql_real_escape_string($subject); $headers = mysql_real_escape_string($headers); $message = mysql_real_escape_string($message); $email = mysql_real_escape_string($email); $result = @mysql_query("INSERT INTO tick_pending (`to`,`from`,`subject`,`headers`,`message`,`source`,`penddate`,`pendtime`) VALUES('$to','$from','$subject','$headers','$message','$email','$todaysdate','$thetime')"); if (mysql_affected_rows() == 0) mail($notify,'Email Logger Error',"There was an error inserting into the email logger database.\n\n".mysql_error()); } else { mail($notify,'Email Logger Error',"There was an error connecting the email logger database.\n\n".mysql_error()); } Here are the results in MySql NOTE: The email was sent from [email protected].. From = "4Domains" <[email protected]> Headers = From [email protected] Sun Jul 18 08:21:53 2010... Source = From [email protected] Sun Jul 18 08:21:53 2010... THE PROBLEM: I need at least one of these to simply save the email address with nothing else, eg; [email protected] Only The Other thing I need help with is in writing a statement whereas if the subject contains [some numbers here] (eg; if subject has brackets with numbers between them) then email info is saved to diff table. Really pulling my hair out. I appreciate any help Link to comment https://forums.phpfreaks.com/topic/208125-problem-with-email-code/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.