0

ここでやろうとしていることは2つありますが、惨めに失敗しており、すべてを試したので理由がわかりません。

  1. 著作権を削除するために使用しようとしてstr_replaceいますが、メールの著作権署名が表示されています。

  2. 何らかの理由で、メッセージのランダムな場所に数字が入力されています。なぜこれが起こっているのか、私は本当に混乱しています。以下は、PHP コードと HTML 出力の外観です。

**** 新しい出力:**** qprint を追加したところ、次のようになりました。 ここに画像の説明を入力

出力: 例

コード:

<?php

/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'username@gmail.com';
$password = 'Password';

/* try to connect */
$inbox = imap_open($hostname, $username, $password) or die('Cannot connect to Gmail: ' . imap_last_error());

/* grab emails */
$emails = imap_search($inbox, 'ALL');

/* if emails are returned, cycle through each... */
if ($emails) {

    /* begin output var */
    $output = '';

    /* put the newest emails on top */
    rsort($emails);

    /* for every email... */
    foreach ($emails as $email_number) {

        /* get information specific to this email */
        $overview = imap_fetch_overview($inbox, $email_number, 0);
        $message = imap_fetchbody($inbox, $email_number, 2);
        $DateFormatted = str_replace("-0500", "", $overview[0] -> date);

        /* output the email header information */
        $output .= '<span class="msg_subject">' . $overview[0] -> subject . '</span> | ';
        $output .= '<span class="msg_date"> ' . $DateFormatted . '</span><br />';

        $bodyFormatted = str_replace("This e-mail (and attachment(s)) is confidential, proprietary, may be subject to copyright and legal privilege and no related rights are waived. If you are not the intended recipient or its agent, any review, dissemination, distribution or copying of this e-mail or any of its content is strictly prohibited and may be unlawful. All messages may be monitored as permitted by applicable law and regulations and our policies to protect our business. E-mails are not secure and you are deemed to have accepted any risk if you communicate with us by e-mail. If received in error, please notify us immediately and delete the e-mail (and any attachments) from any computer or any storage medium without printing a copy.

Ce courriel (ainsi que ses pièces jointes) est confidentiel, exclusif, et peut faire l’objet de droit d’auteur et de privilège juridique; aucun droit connexe n’est exclu. Si vous n’êtes pas le destinataire visé ou son représentant, toute étude, diffusion, transmission ou copie de ce courriel en tout ou en partie, est strictement interdite et peut être illégale. Tous les messages peuvent être surveillés, selon les lois et règlements applicables et les politiques de protection de notre entreprise. Les courriels ne sont pas sécurisés et vous êtes réputés avoir accepté tous les risques qui y sont liés si vous choisissez de communiquer avec nous par ce moyen. Si vous avez reçu ce message par erreur, veuillez nous en aviser immédiatement et supprimer ce courriel (ainsi que toutes ses pièces jointes) de tout ordinateur ou support de données sans en imprimer une copie.", "", $message);
        /* output the email body */
        $output .= '<span class="msg_body">' . $bodyFormatted . '</span><br /><br />';

    }

    echo $output;
}

/* close the connection */
imap_close($inbox);
?>
4

1 に答える 1

2

電子メールがどの形式で送信されているかはわかりませんがimap_qprint($message);、メッセージを正しい形式で取得するために使用する必要があるようですstr_replace('&copy;','',$bodyFormatted);.HTML形式にする必要があるため.

乱数は、imap_qprint() を使用しないことによるものです。メッセージ内に変換が必要な 8 ビット文字列があります。

変更されたコードは次のとおりです。

    /* get information specific to this email */
    $overview = imap_fetch_overview($inbox, $email_number, 0);
    $message = imap_fetchbody($inbox, $email_number, 2);
    $message = imap_qprint($message);
    $DateFormatted = str_replace("-0500", "", $overview[0] -> date);

    /* output the email header information */
    $output .= '<span class="msg_subject">' . $overview[0] -> subject . '</span> | ';
    $output .= '<span class="msg_date"> ' . $DateFormatted . '</span><br />';

    $string = "you should get the HTML and put it in there, I'm sure there are things like &nbsp; and other html chars that it's not finding";
    $bodyFormatted = str_replace($string, "", $message);
    /* output the email body */
    $output .= '<span class="msg_body">' . $bodyFormatted . '</span><br /><br />';
于 2011-11-30T20:05:38.933 に答える