0

我有两件事要在这里做,但我失败得很惨,我已经尝试了一切,所以我不知道原因。

  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 回答