繁体   English   中英

PHP Imap邮件答案

[英]PHP Imap mail answer

我的代码的开始看起来像这样:

$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

这是我为$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.

我只想获得第一行“是的,我会喜欢它!” 这实际上是我的电子邮件的真实答案,因为下面的所有文本均为上一封邮件。

谢谢,

添加:

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

它应该工作。

我有同样的问题,我想获得回复电子邮件的最后一条注册消息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM