duanhuanzhi6431 2014-01-15 06:18
浏览 16

E从Outlook到PHP的邮件

I am having trouble storing data with emails coming from OUTLOOK. I am using a pipe script to store data from incoming emails into an SQL Table but the issue is that if the email is coming from OUTLOOK, it is separated by ; instead of , So the email addresses in the 'TO' or 'CC' field are not stored in the table, only the first addressee gets stored. It works normally with all other emails. How do I tackle this issue ? Here is the code I am using:

#!/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("
", $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]."
";

    // 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]."
";
   }

   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.

".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.

".mysql_error());
} else {
 mail($notify,'Email Logger Error',"There was an error connecting the email logger database.

".mysql_error());
  }

?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
    • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
    • ¥60 pb数据库修改与连接
    • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
    • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
    • ¥20 神经网络Sequential name=sequential, built=False
    • ¥16 Qphython 用xlrd读取excel报错
    • ¥15 单片机学习顺序问题!!
    • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
    • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)