0

I want to extract the sequence of numbers present in the mailbox using imap php. here is my code but it only reads the header of the message. help me

<?php
date_default_timezone_set('Asia/Ho_Chi_Minh');
error_reporting(0);
if (isset($_GET['usermail'])) {
    $hostname = '{imap.yandex.com:993/imap/ssl/novalidate-cert}INBOX';
    $username = $_GET['usermail'];
    $password = $_GET['passmail'];
    $mail = $_GET['mail'];
    if ($username !="" && $password !="") {
        $errorconnect = 
        [
            "status"=>'false',
            "msg"=>'NotConnect'
        ];
        $inbox = imap_open($hostname,$username,$password) or die("Errorlogin");
        $emails = imap_search($inbox,'TO "'.$mail.'"');
        if($emails) {
            $output = '';
            rsort($emails);
            foreach($emails as $email_number) {
                $overview = imap_fetch_overview($inbox,$email_number,0);
                $structure = imap_fetchstructure($inbox, $email_number);
                $getsub = imap_utf8($overview[0]->subject);
                $cutt = explode(" ", $getsub);
                $output = $cutt[0];
            }
            echo "Facebook:".$output;
        }
        else
        {
            echo "errorinbox";
        }
        imap_close($inbox);
    }
    else
    {
        echo "Error";
    }
}
?>

The content of the message looks like this:

Xin chào ABC!
 
Gần đây, bạn đã thêm acb@domain vào tài khoản Facebook của mình.
 
Vui lòng xác nhận địa chỉ email này để chúng tôi có thể cập nhật thông tin liên hệ của bạn.
 
Bạn có thể được yêu cầu nhập mã xác nhận sau: 21635.
 
Xác nhận
 
 
Trân trọng cảm ơn!
Đội ngũ Facebook

I want to extract "21635" it can be random from 5 numbers to 8 numbers.

  • start with https://stackoverflow.com/questions/6766371/php-imap-reading-body-message – ADyson Aug 25 '21 at 16:27
  • @ADyson Can you help me edit my code? – Game Replay Aug 25 '21 at 16:58
  • Why, what problem are you having specifically? Where are you stuck now? I provided you a link to show how to access the message body. Have you used it? Next you need to work out how to parse the numeric value from the message. Is that the issue now...have you researched or tried anything? As a general problem (how to parse specific data from an unstructured set of info) this isn't something new. You should at least be able to get some ideas for possible approaches. It would also help if you can let us know whether the email is HTML or plain text - show us an example of the raw unformatted body – ADyson Aug 25 '21 at 17:28
  • Tks you.i will try it. – Game Replay Aug 26 '21 at 05:49

0 Answers0