Please help....format piped email

Discussion in 'PHP' started by annop, Jun 18, 2008.

  1. #1
    I have a pipe script in my site which is used to save the incoming mail to a particular address by mail forwarding. The problem is-- when the headers are splitted the message body looks like this :-

    mail from Gmail
    ===========

    ------=_Part_32303_1392883.1213689567031
    Content-Type: text/plain; charset=ISO-8859-1
    Content-Transfer-Encoding: 7bit
    Content-Disposition: inline

    Testing Email.

    ------=_Part_32303_1392883.1213689567031
    Content-Type: text/html; charset=ISO-8859-1
    Content-Transfer-Encoding: 7bit
    Content-Disposition: inline

    Testing Email.<br>

    ------=_Part_32303_1392883.1213689567031--



    if the mail is from yahoo the format is different.

    Can anyone please give me a solution to extract only the message from this.

    ie i want to remove the parts like--(------=_Part_32303_1392883.1213689567031
    Content-Type: text/html; charset=ISO-8859-1
    Content-Transfer-Encoding: 7bit
    Content-Disposition: inline)

    Please help.....

    Thanks in advance

     
    annop, Jun 18, 2008 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    Don't get your problem, please specify what your problem is!?
     
    EricBruggema, Jun 18, 2008 IP
  3. annop

    annop Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks Eric,Glad to see someone noticed my post.

    Let me describe the problem.

    ===========================
    In my site say 'mysite.com' there is an email id say 'support@mysite.com'.

    Each mail to this id will be forwarded to a php script(email piping) which splits the email headers like 'From','Subject','Messagebody' etc apart and saves to my DB.

    The problem is after splitting, the message body looks like this:

    ------=_Part_32303_1392883.1213689567031
    Content-Type: text/plain; charset=ISO-8859-1
    Content-Transfer-Encoding: 7bit
    Content-Disposition: inline

    Testing Email.

    ------=_Part_32303_1392883.1213689567031
    Content-Type: text/html; charset=ISO-8859-1
    Content-Transfer-Encoding: 7bit
    Content-Disposition: inline

    Testing Email.<br>

    ------=_Part_32303_1392883.1213689567031--


    =======================

    Here the actual message is 'Testing Email.',and all the other charecters are overheads.I want to remove those parts from the messagebody.

    Can u help me?

    Waiting for ur reply..........
     
    annop, Jun 18, 2008 IP
  4. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Hi, are you be able to post your code pls.
     
    php-lover, Jun 19, 2008 IP
  5. annop

    annop Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5

    Here is the code
    =============

    $fd = fopen("php://stdin", "r");
    $email = "";
    while (!feof($fd)) {
    $email .= fread($fd, 1024);
    }
    fclose($fd);

    // empty vars
    $from = "";
    $replyto = "";
    $subject = "";
    $headers = "";
    $message = "";
    $split = true;


    // handle email
    $lines = explode("\n", $email);



    for ($i=0; $i<count($lines); $i++) {
    if ($split) {
    // 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("/^Reply-To: (.*)/", $lines[$i], $matches)) {
    $replyto = $matches[1];
    }
    } else {
    // not a header, but message
    $message .= $lines[$i]."\n";
    }

    if (trim($lines[$i])=="") {
    // empty line, header section has ended
    $split = false;
    }
    }
    =====================================
    Here $message is the message body.
     
    annop, Jun 19, 2008 IP