The beginning of my code looks like that:
$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>';
}
}
The $message
variable returns the content inside the message, but if the person responds to my email, the previous message sent will be also inside $message
.
Here is an example of output I get for $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.
I would like to get only the first line "Yes I would love it !" which is actually the real answer to my email, because all the text below is the previous mail.
Thanks,
Add this :
$message=explode($message, "\n")[0];
It should work.
我有同样的问题,我想获得回复电子邮件的最后一条注册消息。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.