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,
答案 0 :(得分:0)
添加此内容:
$message=explode($message, "\n")[0];
应该可以。