Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Outlook到PHP的电子邮件_Php_Mysql_Email_Outlook - Fatal编程技术网

从Outlook到PHP的电子邮件

从Outlook到PHP的电子邮件,php,mysql,email,outlook,Php,Mysql,Email,Outlook,我无法通过OUTLOOK发送的电子邮件存储数据。我使用管道脚本将收到的电子邮件中的数据存储到SQL表中,但问题是,如果电子邮件来自OUTLOOK,它将被分隔开;而不是,因此“收件人”或“抄送”字段中的电子邮件地址不存储在表中,只存储第一个收件人。它可以正常处理所有其他电子邮件。我如何处理这个问题?以下是我正在使用的代码: #!/usr/bin/php-cli -c /home/abc/ <?php // Config $dbuser = 'abc_user'; $dbpass =

我无法通过OUTLOOK发送的电子邮件存储数据。我使用管道脚本将收到的电子邮件中的数据存储到SQL表中,但问题是,如果电子邮件来自OUTLOOK,它将被分隔开;而不是,因此“收件人”或“抄送”字段中的电子邮件地址不存储在表中,只存储第一个收件人。它可以正常处理所有其他电子邮件。我如何处理这个问题?以下是我正在使用的代码:

#!/usr/bin/php-cli -c /home/abc/
<?php
    // Config
$dbuser = 'abc_user';
$dbpass = '1234';
$dbname = 'abc_testing';
$dbhost = 'localhost';
$notify= 'abc@def.com'; // an email address required in case of errors
function mailRead($iKlimit = "") 
{ 
if ($iKlimit == "") { 
$iKlimit = 1024; 
} 

// Error strings 
$sErrorSTDINFail = "Error - failed to read mail from STDIN!"; 

// Attempt to connect to STDIN 
$fp = fopen("php://stdin", "r"); 
// Failed to connect to STDIN? (shouldn't really happen) 
if (!$fp) { 
        echo $sErrorSTDINFail; 
        exit(); 
    } 

    // Create empty string for storing message 
    $sEmail = ""; 

    // Read message up until limit (if any) 
    if ($iKlimit == -1) { 
        while (!feof($fp)) { 
            $sEmail .= fread($fp, 1024); 
        }                     
    } else { 
        while (!feof($fp) && $i_limit < $iKlimit) { 
            $sEmail .= fread($fp, 1024); 
            $i_limit++; 
        }         
    } 

    // Close connection to STDIN 
    fclose($fp); 

    // Return message 
    return $sEmail; 
}  
$email = mailRead();

// 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 emails (`FROM`,`SUBJECT`,`TO`,`CC`) VALUES('$from','$subject','$to','$headers')");
 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());
  }

?>
#/usr/bin/php cli-c/home/abc/