【问题标题】:PHP Imap mail answerPHP Imap 邮件回复
【发布时间】:2019-01-18 19:01:58
【问题描述】:

我的代码开头是这样的:

$hostname = '{**HOST**}';
$username = '**USERNAME**';
$password = '**PASSWORD**';
$inbox = imap_open($hostname,$username,$password);



$emails = imap_search($inbox,'ALL');

if($emails)
{
    $output = '';

    rsort($emails);

    foreach($emails as $email_number)
    {

        $header=imap_headerinfo($inbox,$email_number);

        $from = $header->from[0]->mailbox . "@" . $header->from[0]->host;
        $toaddress=$header->toaddress;
        $replyto=$header->reply_to[0]->mailbox."@".$header->reply_to[0]->host;
        $datetime=date("Y-m-d H:i:s",$header->udate);
        $subject=imap_utf8($header->subject);

        //remove the " from the $toaddress
        $toaddress = str_replace('"','',$toaddress);

        echo '<strong>To:</strong> '.$toaddress.'<br>';
        echo '<strong>From:</strong> '.$from.'<br>';
        echo '<strong>Subject:</strong> '.$subject.'<br>';
                echo '<strong>date:</strong> '.$datetime.'<br>';

        //get message body
        $message = quoted_printable_decode(imap_fetchbody($inbox,$email_number,1.1));
        if($message == '')
        {
            $message = quoted_printable_decode(imap_fetchbody($inbox,$email_number,1));
        }
        echo '<strong>msg:</strong> '.$message.'<br><br>';
    }
}

$message 变量返回邮件内的内容,但如果此人回复我的电子邮件,之前发送的邮件也会在 $message 内。

这是我为$message 获得的输出示例:

Yes I would love it !


Le vendredi, janvier 18, 2019, 5:49 PM, test <test@xtestx.fr> a écrit :

Bonjour, 
Merci de nous avoir contactés. 

Aimez-vous faire cela ?

Si vous souhaitez d'autres informations, n'hésitez pas à répondre directement à ce mail. 

Cordialement, 
L'équipe.

我只想得到第一行“是的,我会喜欢它!”这实际上是我邮件的真正答案,因为下面所有的文字都是以前的邮件。

谢谢,

【问题讨论】:

  • 据我所知,我认为引用实际上是已发送电子邮件的一部分。这几乎是不可能去掉的,因为引用风格可能会因发件人的邮件客户端而异
  • 我不知道该怎么做,但也许所有的邮件客户端都有 在我想摆脱的第一行。类似于 preg 匹配的东西,它删除了第一行,然后是所有其他行
  • 如果我刚刚向您发送了一条消息,其中包括许多其他详细信息,我还向您提供了我从 VCard 复制的联系人的邮件地址,会发生什么情况。看起来像这样:Some text (even containing line breaks)... Here's the contact: (line break) "Some Name &lt;some.name@example.com&gt;" (line break) ... continuation of my message?没有引用。您仍然会使用这种方法将下面的部分作为引用

标签: php email imap


【解决方案1】:

添加这个:

$message=explode($message, "\n")[0];

它应该可以工作。

【讨论】:

  • 您好 Jaime,您可以编辑您的答案以改进它。
  • 您好,如果用户发送的消息中包含换行符,它将只保存第一行:/ 例如:'您好,您好吗\n\n 感谢您回答我的问题\n\n 我非常喜欢它”只会保存 «你好,你好吗»
猜你喜欢
  • 2016-07-09
  • 1970-01-01
  • 2010-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多